Unit testing is possible in particle boards

Hi everyone
I have a doubt is unit testing possible in particle code that testing the code in advance before flashing. Bcoz the code runs after flashing. If so please let me know the library for doing it.
Thanks in advance

1 Like

If you mean a device emulator - there isn’t one. Particle Workbench is bringing a better toolset including local compile and debug. I would have a look in that area as to whether these are the tools you seek.

While you can’t emulate the whole Particle API, one option is to just implement a few common APIs like String. For example, in the JsonParserGeneratorRK library, I factored out all of the parsing code into a unit testable module. It’s in the test directory in the Github repo below.

One of the nice things about doing the unit tests this way is that you can run them natively. This is especially useful under Linux as you can run them natively with valgrind, which checks for memory leaks, overruns, underruns, bad pointers, using freed blocks, etc…


Thanks for ur response I was not mentioning about emulator based debugging I was meaning do we have any particular library for performing TDD

Please reply me

What is TDD?

TDD is called as test driven development it’s a process that relies on the repetition of a very short development cycle

I just want to clarify is their any Library like Arduino unit test that Arduino ide has in particle

Please reply I’m still waiting for Ur response

Hi @Lakshmi

Particle has written their own unit test framework which you can see in use on github in their device-os/user/tests/unit/ directory. I don’t know much about it but it looks like it is macro based. They have a variety of other test frameworks, including one that is run on specific hardware for peripheral tests.

If you are talking about Matthew Murdoch’s Arduinounit, I have looked at that I think it could be ported to the Particle environment by someone with the desire and a bit of time. Most of it would likely just work but I’m sure a few things with pin-names or something would come up that needed to be fixed.

It is not clear to me if you are asking, “Does Particle use a unit testing framework in-house?” in which the answer is yes, of course; Or are you asking “Is there a unit testing framework for Particle that I can use?” for which the answer is yes, but you will need to do some work customizing or porting it, depending on which framework you pick.


Thank you so much my question was is particle has unit testing framework which I can use and the answer is quite clear. I will start to work on it

I have ported a unit test framework called Aunit from Arduino. I am just getting to understand and use this as I am also learning about Test Driven Development for embedded C/C++. Trying to gauge if there is any interest in this in the community? If there is I could develop some tutorials perhaps with some advice from @bsatrom .


I would love to see TDD content and tutorials for embedded, and I’m sure many others would as well! @armor happy to provide any help or guidance I can here!


Any progress on this? I’m currently performing unit tests with a dedicated ‘test’ board and sketch that performs tests in setup(). Works ok and give me complete control. The part I don’t like so far about it is that I have to give my UnitTest class (where the tests are) “friend” access to the classes being tested. Better code design might eventually resolve that, though.

@ronlisle I did manage to port AUnit (for Arduino) to Particle GitHub - bxparks/AUnit: Unit testing framework for Arduino platforms inspired by ArduinoUnit and Google Test. Used with AUniter or UnixHostDuino for continuous builds. - but like a lot of things at start of lock down I thought I would have lots of free time and then didn’t have the time to properly start using it in Test Driven Development and certainly not to write tutorials.

The basic unit test 101 looks like this

#include "Particle.h"

// Same as ../basic/basic.ino except this uses <AUnitVerbose.h> instead of
// <AUnit.h> to get the more verbose assertion messages containing the string
// fragment of the actual arguments in the assertXxx() macros. The cost is
// ~20-25% increase in flash memory to store those strings for moderate to
// large unit tests. But the verbose version may be helpful for debugging.

#include "AUnit.h"

  int x = 1;
  assertEqual(x, 1);

  int x = 1;
  assertNotEqual(x, 1);

void setup()

void loop()
  // Should get:
  // TestRunner summary:
  //    1 passed, 1 failed, 0 skipped, 0 timed out, out of 2 test(s).