33A unit testing framework for Arduino platforms inspired by ArduinoUnit and
44Google Test.
55
6- Version: 0.4.1 (2018-04-06 )
6+ Version: 0.4.2 (2018-04-10 )
77
88## Summary
99
@@ -89,7 +89,10 @@ Here are the features in AUnit which are not available in ArduinoUnit:
8989 * ` checkTestXxxF() `
9090 * ` externTestF() `
9191 * ` externTestingF() `
92- * AUnit works on the ESP8266 platform.
92+ * AUnit supports the ` teardown() ` method to clean up test fixtures after
93+ the ` setup() ` method.
94+ * AUnit is tested on the AVR (8-bit), Teensy ARM (32-bit) , and ESP8266 (32-bit)
95+ Arduino platforms.
9396* Test filters (` TestRunner::include() ` and ` TestRunner::exclude() ` ) support the
9497 same 2 arguments versions corresponding to ` testF() ` and ` testingF() `
9598
@@ -196,11 +199,11 @@ Here is a rough outline of an AUnit unit test sketch:
196199using namespace aunit;
197200
198201test(example_test) {
199- ... assertXxx() ...
202+ ...assertXxx()...
200203}
201204
202205testing(looping_test) {
203- ... code ...
206+ ...code...
204207 if (...) {
205208 pass();
206209 } else if (...) {
@@ -215,17 +218,17 @@ class CustomTestOnce: public TestOnce {
215218 // optional
216219 virtual void setup() override {
217220 TestOnce::setup();
218- ...set up code...
221+ ...setup code...
219222 }
220223
221224 // optional
222225 virtual void teardown() override {
223- ...tear down code...
226+ ...teardown code...
224227 TestOnce::teardown();
225228 }
226229
227230 void assertBigStuff() {
228- ... higher level assertions ...
231+ ...higher level assertions...
229232 }
230233};
231234
@@ -240,12 +243,12 @@ class CustomTestAgain: public TestAgain {
240243 // optional
241244 virtual void setup() override {
242245 TestAgain::setup();
243- ...set up code...
246+ ...setup code...
244247 }
245248
246249 // optional
247250 virtual void teardown() override {
248- ...tear down code...
251+ ...teardown code...
249252 TestOnce::teardown();
250253 }
251254
@@ -408,30 +411,41 @@ To create a test fixture:
4084111 . Derives a new class from either ` TestOnce ` (if you want to run the test just
409412 once), or ` TestAgain ` (if you want to run the test repeatedly).
4104131 . Add any data objects inside the class.
411- 1 . Add a ` void setup() {...} ` method to perform any common
414+ 1 . Optionally add a ` virtual void setup() {...}` method to perform any common
412415 initialization code. Be sure to call the parent's ` setup() ` method in the
413- first line to chain any ` setup() ` methods defined by the parents. There may
416+ * first* line to chain any ` setup() ` methods defined by the parents. There may
414417 be multiple parent classes.
418+ 1 . Optionally add a ` virtual void teardown() {...} ` method to perform any common
419+ clean up code. Be sure to call the parent's ` teardown() ` method in the * last*
420+ line to chain any ` teardown() ` methods defined by the parents. There may be
421+ multiple parent classes.
4154221 . Add any additional shared methods into this new class.
416423
417424To define your tests, use the ` testF() ` macro like this:
418425```
419426class CustomTestOnce: public TestOnce {
420427 protected:
428+ // optional
421429 virtual void setup() override {
422- TestOnce::setup(); // chain the parent's setup()
423- ... setup code ...
430+ TestOnce::setup();
431+ ...setup code...
432+ }
433+
434+ // optional
435+ virtual void teardown() override {
436+ ...teardown code...
437+ TestOnce::teardown();
424438 }
425439
426440 void assertCustomStuff() {
427- ... common code ...
441+ ...common code...
428442 }
429443
430444 int sharedValue;
431445};
432446
433447testF(CustomTestOnce, calculate) {
434- ... test code here ...
448+ ...test code here...
435449}
436450```
437451No constructor for ` CustomTestOnce ` needs to be defined.
@@ -447,20 +461,27 @@ To define a continuous test, use the `testingF()` macro like this:
447461```
448462class CustomTestAgain: public TestAgain {
449463 protected:
464+ // optional
450465 virtual void setup() override {
451- TestOnce::setup(); // chain the parent's setup()
452- ... setup code ...
466+ TestAgain::setup();
467+ ...setup code...
468+ }
469+
470+ // optional
471+ virtual void teardown() override {
472+ ...teardown code...
473+ TestAgain::teardown();
453474 }
454475
455476 void assertCustomStuff() {
456- ... common code ...
477+ ...common code...
457478 }
458479
459480 int sharedValue;
460481};
461482
462483testingF(CustomTestAgain, calculate) {
463- ... test code here ...
484+ ...test code here...
464485}
465486```
466487
@@ -471,8 +492,9 @@ Similarly, the `testingF()` macro creates a subclass named
471492See ` examples/fixtures/fixtures.ino ` to see a working example of the ` testF() `
472493macro.
473494
474- *** ArduinoUnit Compatibility*** : _ The ` testF() ` and ` testingF() ` macros
475- are available only in AUnit (and Google Test), not ArduinoUnit._
495+ *** ArduinoUnit Compatibility*** : _ The ` testF() ` and ` testingF() ` macros,
496+ and the ` teardown() ` virtual method are available only in AUnit (and Google
497+ Test), not ArduinoUnit._
476498
477499### Early Return and Delayed Assertions
478500
@@ -491,9 +513,16 @@ then `doStuff()` inside `testF()` will execute:
491513```
492514class CustomTestOnce: public TestOnce {
493515 protected:
516+ // optional
494517 virtual void setup() override {
495- TestOnce::setup(); // chain the parent's setup()
496- ... setup code ...
518+ TestOnce::setup();
519+ ...setup code...
520+ }
521+
522+ // optional
523+ virtual void teardown() override {
524+ ...teardown code...
525+ TestOnce::teardown();
497526 }
498527
499528 void assertCustomStuff() {
@@ -610,6 +639,7 @@ available in AUnit._
610639The following methods are defined at the ` Test ` base class level:
611640
612641* ` setup() `
642+ * ` teardown() `
613643
614644The ` TestOnce ` class defines:
615645* ` once() `
@@ -618,8 +648,9 @@ The `TestAgain` class defines:
618648* ` again() `
619649
620650*** ArduinoUnit Compatibility*** : _ These are functionally the same as ArduinoUnit
621- except with different class names. Instead of ` Test ` use ` TestAgain ` , Instead
622- of ` Test::loop ` , use ` TestAgain::again() ` ._
651+ except with different class names. Instead of ` Test ` use ` TestAgain ` . Instead
652+ of ` Test::loop ` use ` TestAgain::again() ` . ArduinoUnit does not support a
653+ ` teardown() ` method._
623654
624655### Running the Tests
625656
@@ -655,7 +686,6 @@ We can `exclude()` or `include()` test cases using a pattern match:
655686* ` TestRunner::include(pattern) `
656687* ` TestRunner::include(testClass, pattern) `
657688
658-
659689These methods are called from the global ` setup() ` method:
660690
661691```
@@ -668,6 +698,10 @@ void setup() {
668698}
669699```
670700
701+ Excluded tests bypass their ` setup() ` and ` teardown() ` methods and terminate
702+ immidiately. For the purposes of reporting, however, excluded tests are
703+ counted as "skipped".
704+
671705The 2-argument versions of ` include() ` and ` exclude() ` correspond to the
6727062 arguments of ` testF() ` and ` testingF() ` .
673707
@@ -905,9 +939,16 @@ messages for successful assertions (with a
905939```
906940class CustomTestOnce: public TestOnce {
907941 protected:
942+ // optional
908943 virtual void setup() override {
909- TestOnce::setup(); // chain the parent's setup()
910- ... setup code ...
944+ TestOnce::setup();
945+ ...setup code...
946+ }
947+
948+ // optional
949+ virtual void teardown() override {
950+ ...teardown code...
951+ TestOnce::teardown();
911952 }
912953
913954 void assertCustomStuff() {
@@ -926,7 +967,7 @@ class CustomTestOnce: public TestOnce {
926967testF(CustomTestOnce, calculate) {
927968 enableVerbosity(Verbosity::kAssertionPassed);
928969
929- ... test code here ...
970+ ...test code here...
930971 assertCustomStuff();
931972}
932973```
0 commit comments