# Unit test library \[PORTED\]

**URL:** <https://community.particle.io/t/unit-test-library-ported/5318>\
**Category:** Libraries\
**Created:** [June 25, 2014, 2:19am UTC](https://community.particle.io/t/unit-test-library-ported/5318 "2014-06-25T02:19:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)\
**Post date:** [June 25, 2014, 2:19am UTC](https://community.particle.io/t/unit-test-library-ported/5318/1 "2014-06-25T02:19:26Z")

</div>

This is the ArduinoUnit library that I’ve ported - it allows you to create and run tests on the spark.

[https://github.com/m-mcgowan/spark-unit-test](https://github.com/m-mcgowan/spark-unit-test)

An example:

```
test(ok) 
{
  int x=3;
  int y=3;
  assertEqual(x,y);
}

test(bad)
{
  int x=3;
  int y=3;
  assertNotEqual(x,y);
}

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Test::run();
}

```

It’s nicer than some other test frameworks in that you don’t have to manually register a list of tests.

I used this library to run on-device tests for my flashee library - [take a look](https://github.com/m-mcgowan/spark-flashee-eeprom/blob/master/firmware/examples/integration-tests.cpp) at those tests if you want to see a real-world example. (Although they are better called integration tests they exercise the the library + the flash hardware.)

---

<div class="post-metadata">

**Author:** ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)\
**Post date:** [August 17, 2014, 10:39pm UTC](https://community.particle.io/t/unit-test-library-ported/5318/2 "2014-08-17T22:39:55Z")

</div>

Version 0.1.1 published!

The previous version was a straight port of the Arduino code. This version adds features unique to the Spark:

- when running, the RGB led indicates the overall test health
- include or exclude tests at runtime via cloud functions
- waits to run tests until either ‘t’ is received over serial or cloud function is called
- test stats (`passed`/`failed`/`skipped`/`count`) available as cloud variables
- test running state (`waiting`, `running`, `complete`) available as a variable,  
and changes to running state are published as events.
- less boilerplate code - setup()/loop() can be replaced with `UNIT_TEST_APP()` macro.

These changes make the unit test runner more pleasant to use when manually running tests, and also provide the hooks to integrate this into an automated build/test environment.

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [August 17, 2014, 10:59pm UTC](https://community.particle.io/t/unit-test-library-ported/5318/3 "2014-08-17T22:59:35Z")

</div>

Ah nice! I realized yesterday while using the `enterDFU()` function and it seems like once it enters the mode, pressing the **RST** button does not bring it out of the state.

Will post back if i have an alternative, friendlier `enterDFU()` via the Spark function call. 😉

---

<div class="post-metadata">

**Author:** ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)\
**Post date:** [August 17, 2014, 11:03pm UTC](https://community.particle.io/t/unit-test-library-ported/5318/4 "2014-08-17T23:03:23Z")

</div>

I noticed that too, you have to flash an image which will then reset the system flags.

I was wondering if this was available now as part of the recent 'System.xxx()` functions - if not, it would be a great addition. Although keep in mind that if calling this from a spark function to not call it directly, but to set a flag and reset from the main loop, otherwise the spark cloud hangs waiting for a response.

EDIT: yeah, `System.bootloader()` does the same thing, but also comments there indicating that it stays in bootloader mode (dfu) even after a reset until firmware is loaded.

---

<div class="post-metadata">

**Author:** ![gusgonnet](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/gusgonnet/32/27491_2.png) [@gusgonnet](https://community.particle.io/u/gusgonnet)\
**Post date:** [April 2, 2016, 6:41pm UTC](https://community.particle.io/t/unit-test-library-ported/5318/5 "2016-04-02T18:41:44Z")

</div>

Hi, on a related note, I wrote about one way of system testing projects based in Particles here:

[Verify your projects behave as intended with a telecom grade test tool](https://www.hackster.io/gusgonnet/how-to-test-your-projects-with-titan-a633f2)

[![](https://hackster.imgix.net/uploads/cover_image/file/124240/pia18322_1041.jpg?w=400&h=350&fit=min&fm=jpg) ](https://hackster.imgix.net/uploads/cover_image/file/124240/pia18322_1041.jpg?w=400&h=350&fit=min&fm=jpg)

Thanks,  
Gustavo.

---

<div class="post-metadata">

**Author:** ![Jairbearrr](https://avatars.discourse-cdn.com/v4/letter/j/dfb087/32.png) [@Jairbearrr](https://community.particle.io/u/Jairbearrr)\
**Post date:** [May 27, 2016, 6:31pm UTC](https://community.particle.io/t/unit-test-library-ported/5318/6 "2016-05-27T18:31:36Z")

</div>

Hi,

I’m using the Particle Photon, and I have run into quite a few errors during compliation, most notably it it not recognizing the the `System.bootloader();` line. What spark/particle board did you use, and can you give some more details on how you set it up?
