Skip to content

Commit 0d12224

Browse files
authored
Merge pull request #22 from bxparks/develop
merge 0.4.2
2 parents 4f6a241 + 694d92e commit 0d12224

File tree

12 files changed

+269
-112
lines changed

12 files changed

+269
-112
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Changelog
22

3+
* 0.4.2 (2018-04-10)
4+
* Fix FSM for excluded tests so that they bypass setup() and teardown().
35
* 0.4.1 (2018-04-06)
46
* Add support for `Test::teardown()` for use in test fixtures.
57
* Add 2-argument versions of `TestRunner::include()` and

README.md

Lines changed: 70 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
A unit testing framework for Arduino platforms inspired by ArduinoUnit and
44
Google 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:
196199
using namespace aunit;
197200
198201
test(example_test) {
199-
... assertXxx() ...
202+
...assertXxx()...
200203
}
201204
202205
testing(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:
408411
1. 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).
410413
1. 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.
415422
1. Add any additional shared methods into this new class.
416423

417424
To define your tests, use the `testF()` macro like this:
418425
```
419426
class 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
433447
testF(CustomTestOnce, calculate) {
434-
... test code here ...
448+
...test code here...
435449
}
436450
```
437451
No constructor for `CustomTestOnce` needs to be defined.
@@ -447,20 +461,27 @@ To define a continuous test, use the `testingF()` macro like this:
447461
```
448462
class 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
462483
testingF(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
471492
See `examples/fixtures/fixtures.ino` to see a working example of the `testF()`
472493
macro.
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
```
492514
class 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._
610639
The following methods are defined at the `Test` base class level:
611640

612641
* `setup()`
642+
* `teardown()`
613643

614644
The `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-
659689
These 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+
671705
The 2-argument versions of `include()` and `exclude()` correspond to the
672706
2 arguments of `testF()` and `testingF()`.
673707

@@ -905,9 +939,16 @@ messages for successful assertions (with a
905939
```
906940
class 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 {
926967
testF(CustomTestOnce, calculate) {
927968
enableVerbosity(Verbosity::kAssertionPassed);
928969
929-
... test code here ...
970+
...test code here...
930971
assertCustomStuff();
931972
}
932973
```

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=AUnit
2-
version=0.4.1
2+
version=0.4.2
33
author=Brian T. Park <[email protected]>
44
maintainer=Brian T. Park <[email protected]>
55
sentence=A unit testing framework for Arduino platforms inspired by ArduinoUnit and Google Test.

src/AUnit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ SOFTWARE.
4444
#include "aunit/TestMacro.h"
4545

4646
// Version format: xxyyzz == "xx.yy.zz"
47-
#define AUNIT_VERSION 000401
47+
#define AUNIT_VERSION 000402
4848

4949
#endif

src/aunit/Test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ Test** Test::getRoot() {
4747
}
4848

4949
Test::Test():
50-
mStatus(kStatusNew),
50+
mLifeCycle(kLifeCycleNew),
51+
mStatus(kStatusUnknown),
5152
mVerbosity(Verbosity::kNone),
5253
mNext(nullptr) {
5354
}
@@ -56,7 +57,7 @@ Test::Test():
5657
// status as kStatusSetup to allow testing() test cases to continue.
5758
void Test::setPassOrFail(bool ok) {
5859
if (!ok) {
59-
mStatus = kStatusFailed;
60+
setStatus(kStatusFailed);
6061
}
6162
}
6263

0 commit comments

Comments
 (0)