Skip to content

Commit b042c64

Browse files
authored
Merge pull request #4 from bxparks/develop
v0.3.0: implement all remaining macros from ArduinoUnit
2 parents 609eb0e + ffe1782 commit b042c64

File tree

13 files changed

+691
-67
lines changed

13 files changed

+691
-67
lines changed

CHANGELOG.md

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

3+
* v0.3.0 (2018-03-19)
4+
* Implement all remaining macros from ArduinoUnit:
5+
assertTestXxx(), checkTestXxx(), externTest(), externTesting().
36
* v0.2.0 (2018-03-16)
47
* TestRunner can time out long running tests. Default time out is 10
58
seconds, but is configurable using TestRunner::setTimeout().

README.md

Lines changed: 66 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# AUnit - Unit Testing Framework for Arduino Platforms
22

3+
Version: v0.3.0 (2018-03-19)
4+
35
## Summary
46

57
**AUnit** (rhymes with "JUnit") is a unit testing framework based
@@ -16,8 +18,9 @@ AUnit was created to solve 2 problems with ArduinoUnit:
1618
[ArduinoUnit#70](https://github.com/mmurdoch/arduinounit/issues/70).
1719
* ArduinoUnit does not compile on the ESP8266 platform (see
1820
[ArduinoUni#68](https://github.com/mmurdoch/arduinounit/issues/68),
19-
[ArduinoUni#57](https://github.com/mmurdoch/arduinounit/pull/57), and
20-
[ArduinoUni#55](https://github.com/mmurdoch/arduinounit/issues/55)).
21+
[ArduinoUni#57](https://github.com/mmurdoch/arduinounit/pull/57),
22+
[ArduinoUni#55](https://github.com/mmurdoch/arduinounit/issues/55),
23+
[ArduinoUni#54](https://github.com/mmurdoch/arduinounit/issues/54)).
2124

2225
In contrast:
2326
* AUnit consumes as much as 66% *less* flash memory than ArduinoUnit on the
@@ -31,11 +34,16 @@ convert to AUnit:
3134
* `#include <ArduinoUnit.h>` -> `#include <AUnit.h>`
3235
* `Test::run()` -> `aunit::TestRunner::run()`
3336

34-
Almost all of the frequently used macros are compatible between ArduinoUnit and
37+
Essentially all of the various macros are compatible between ArduinoUnit and
3538
AUnit:
3639
* `test()`
3740
* `testing()`
3841
* `assertXxx()`
42+
* Meta Assertions
43+
* `checkTestXxx()`
44+
* `assertTestXxx()`
45+
* `externTest()`
46+
* `externTesting()`
3947

4048
AUnit supports exclude and include filters:
4149
* `TestRunner::exclude()`
@@ -48,15 +56,19 @@ Here are the features which have not been ported over from ArduinoUnit:
4856
* ArduinoUnit supports multiple `*` wildcards in its `exclude()` and `include()`
4957
methods. AUnit supports only a single `*` wildcard and it must occur at the
5058
end if present.
51-
* Various "Meta Assertions" from ArduinoUnit (i.e. `checkTestXxx()` and
52-
`assertTestXxx()`) have not been implemented.
5359

5460
### Added Features
5561

56-
Here are some features in AUnit, not available in ArduinoUnit:
62+
Here are the features in AUnit which are not available in ArduinoUnit:
5763

5864
* The `TestRunner` supports a configurable timeout parameter which
59-
can prevent `testing()` test cases from running forever.
65+
can prevent `testing()` test cases from running forever. The following
66+
methods and macros are available in AUnit to support this feature:
67+
* `Test::expire()`
68+
* `assertTestExpire()`
69+
* `assertTestNotExpire()`
70+
* `checkTestExpire()`
71+
* `checkTestNotExpire()`
6072
* AUnit works on the ESP8266 platform.
6173

6274
### Beta Status
@@ -67,14 +79,16 @@ it currently in "beta stage" until more users have tested it.
6779

6880
## Installation
6981

70-
The library is available in the Arduino IDE Library Manager. Search for "unit
71-
test" or "AUnit", select "AUnit", then click the "Install" button.
82+
The latest stable release is available in the Arduino IDE Library Manager.
83+
Search for "unit test" or "AUnit", select "AUnit", then click the "Install"
84+
button.
7285

73-
The library can also be installed by cloning the
74-
[GitHub repository](https://github.com/bxparks/AUnit), then
75-
manually copying over the contents to the `./libraries` directory used
76-
by the Arduino IDE. (The result is a directory named `./libraries/AUnit`.)
77-
See the Preferences menu for the location of the Arduino sketch directory.
86+
The development version can be installed by cloning the
87+
[GitHub repository](https://github.com/bxparks/AUnit), checking out the
88+
`develop` branch, then manually copying over the contents to the `./libraries`
89+
directory used by the Arduino IDE. (The result is a directory named
90+
`./libraries/AUnit`.) See the Preferences menu for the location of the Arduino
91+
sketch directory. The `master` branch contains the stable release.
7892

7993
Using either installation method, you may need to restart the Arduino IDE to
8094
pick up the new library.
@@ -310,9 +324,7 @@ The following boolean asserts are also available:
310324

311325
### Meta Assertions
312326

313-
***ArduinoUnit Compatibility***: _Not implemented in AUnit._
314-
315-
The following methods from ArduinoUnit are not implemented:
327+
The following methods from ArduinoUnit have also been implemented:
316328

317329
* `checkTestDone(name)`
318330
* `checkTestNotDone(name)`
@@ -322,6 +334,8 @@ The following methods from ArduinoUnit are not implemented:
322334
* `checkTestNotFail(name)`
323335
* `checkTestSkip(name)`
324336
* `checkTestNotSkip(name)`
337+
* `checkTestExpire(name)` [&ast;]
338+
* `checkTestNotExpire(name)` [&ast;]
325339
* `assertTestDone(name)`
326340
* `assertTestNotDone(name)`
327341
* `assertTestPass(name)`
@@ -330,14 +344,38 @@ The following methods from ArduinoUnit are not implemented:
330344
* `assertTestNotFail(name)`
331345
* `assertTestSkip(name)`
332346
* `assertTestNotSkip(name)`
347+
* `assertTestExpire(name)` [&ast;]
348+
* `assertTestNotExpire(name)` [&ast;]
333349

334-
The following macros are not implemented because they are only needed
335-
by the Meta Assertions:
350+
The `checkTestXxx()` methods check the status of the test named `name`
351+
and returns a `bool`. The execution continues even if `false`.
352+
353+
The `assertTestXxx()` methods stops the unit test if the status check
354+
returns `false`, and prints assertion messages that look like this:
355+
```
356+
Assertion passed: Test slow_pass is done, file AUnitTest.ino, line 366.
357+
Assertion passed: Test slow_pass is not failed, file AUnitTest.ino, line 372.
358+
Assertion passed: Test slow_skip is skipped, file AUnitTest.ino, line 448.
359+
```
360+
361+
The following macros define `extern` references to test case objects which live
362+
in other `.cpp` files. These are required for the above meta assertions if the
363+
test cases are defined in another file:
336364

337365
* `externTest()`
338366
* `externTesting()`
339367

340-
***ArduinoUnit Compatibility***: _Not implemented in AUnit._
368+
***ArduinoUnit Compatibility***: _The methods marked by [&ast;] are only
369+
available in AUnit. Also, the assertion messages are different. ArduinoUnit
370+
reuses the format used by the `assertXxx()` macros, so prints something like
371+
the following:_
372+
```
373+
Assertion passed: (test_slow_skip_instance.state=2) >= (Test::DONE_SKIP=2), file
374+
AUnitTest.ino, line 439.
375+
```
376+
377+
_AUnit has a separate message handler to print a customized message for the
378+
assertTestXxx() meta assertion macros._
341379

342380
### Status Indicator Methods
343381

@@ -348,9 +386,10 @@ status reason).
348386
* `pass()` - test passed
349387
* `fail()` - test failed
350388
* `skip()` - test skipped
351-
* `expire()` - test timed out
389+
* `expire()` - test timed out [&ast;]
352390

353-
***ArduinoUnit Compatibility***: _`expire()` is available only in AUnit._
391+
***ArduinoUnit Compatibility***: _The method(s) marked by [&ast;] are only
392+
available in AUnit._
354393

355394
### Overridable Methods
356395

@@ -627,11 +666,11 @@ Teensy LC (static) | 8192 | 2980 | 2780 |
627666
Teensy 3.2 (flash) | 262144 | 51236 | 36300 |
628667
Teensy 3.2 (static) | 65536 | 5328 | 5236 |
629668
---------------------------+---------+-------------+-------------|
630-
ESP8266 - ESP-12E (flash) | 1044464 | does not | 267479 |
631-
ESP8266 - ESP-12E (static) | 81920 | compile | 34564 |
669+
ESP8266 - ESP-12E (flash) | 1044464 | does not | 266748 |
670+
ESP8266 - ESP-12E (static) | 81920 | compile | 33128 |
632671
---------------------------+---------+-------------+-------------|
633-
ESP8266 - ESP-01 (flash) | 499696 | does not | 267359 |
634-
ESP8266 - ESP-01 (static) | 47356 | compile | 34564 |
672+
ESP8266 - ESP-01 (flash) | 499696 | does not | 266748 |
673+
ESP8266 - ESP-01 (static) | 47356 | compile | 33128 |
635674
---------------------------+---------+-------------+-------------|
636675
```
637676

@@ -647,7 +686,7 @@ See [CHANGELOG.md](CHANGELOG.md).
647686
This library was developed and tested using:
648687
* [Arduino IDE 1.8.5](https://www.arduino.cc/en/Main/Software)
649688
* [Teensyduino 1.41](https://www.pjrc.com/teensy/td_download.html)
650-
* [ESP8266 Arduino Core 2.4.0](https://arduino-esp8266.readthedocs.io/en/2.4.0-rc2/)
689+
* [ESP8266 Arduino Core 2.4.1](https://arduino-esp8266.readthedocs.io/en/2.4.1/)
651690

652691
I used MacOS 10.13.3 for most of my development.
653692

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
#line 2 "meta_asserts.ino"
2+
3+
// Originally derived from the README.md in
4+
// https://github.com/mmurdoch/arduinounit/ but is now very different.
5+
6+
#define USE_AUNIT 0
7+
8+
#if USE_AUNIT == 1
9+
#include <AUnit.h>
10+
using aunit::TestRunner;
11+
using aunit::Verbosity;
12+
#else
13+
#include <ArduinoUnit.h>
14+
#define assertTestExpire(x)
15+
#define assertTestNotExpire(x)
16+
#define checkTestExpire(x) true
17+
#define checkTestNotExpire(x) true
18+
#endif
19+
20+
testing(slow_pass) { if (millis() > 1000) pass(); }
21+
22+
testing(slow_fail) { if (millis() > 1000) fail(); }
23+
24+
testing(slow_skip) { if (millis() > 1000) skip(); }
25+
26+
#if USE_AUNIT == 1
27+
testing(slow_expire) { if (millis() > 1000) expire(); }
28+
#endif
29+
30+
testing(slow_pass_monitor) {
31+
unsigned long now = millis();
32+
if (now < 1000) {
33+
assertTestNotDone(slow_pass);
34+
assertTrue(checkTestNotDone(slow_pass));
35+
36+
assertTestNotPass(slow_pass);
37+
assertTrue(checkTestNotPass(slow_pass));
38+
39+
assertTestNotFail(slow_pass);
40+
assertTrue(checkTestNotFail(slow_pass));
41+
42+
assertTestNotSkip(slow_pass);
43+
assertTrue(checkTestNotSkip(slow_pass));
44+
45+
assertTestNotExpire(slow_pass);
46+
assertTrue(checkTestNotExpire(slow_pass));
47+
}
48+
if (now > 2000) {
49+
assertTestDone(slow_pass);
50+
assertTrue(checkTestDone(slow_pass));
51+
52+
assertTestPass(slow_pass);
53+
assertTrue(checkTestPass(slow_pass));
54+
55+
assertTestNotFail(slow_pass);
56+
assertTrue(checkTestNotFail(slow_pass));
57+
58+
assertTestNotSkip(slow_pass);
59+
assertTrue(checkTestNotSkip(slow_pass));
60+
61+
assertTestNotExpire(slow_pass);
62+
assertTrue(checkTestNotExpire(slow_pass));
63+
64+
pass();
65+
}
66+
}
67+
68+
testing(slow_fail_monitor) {
69+
unsigned long now = millis();
70+
if (now < 1000) {
71+
assertTestNotDone(slow_fail);
72+
assertTrue(checkTestNotDone(slow_fail));
73+
74+
assertTestNotPass(slow_fail);
75+
assertTrue(checkTestNotPass(slow_fail));
76+
77+
assertTestNotFail(slow_fail);
78+
assertTrue(checkTestNotFail(slow_fail));
79+
80+
assertTestNotSkip(slow_fail);
81+
assertTrue(checkTestNotSkip(slow_fail));
82+
83+
assertTestNotExpire(slow_fail);
84+
assertTrue(checkTestNotExpire(slow_fail));
85+
}
86+
if (now > 2000) {
87+
assertTestDone(slow_fail);
88+
assertTrue(checkTestDone(slow_fail));
89+
90+
assertTestNotPass(slow_fail);
91+
assertTrue(checkTestNotPass(slow_fail));
92+
93+
assertTestFail(slow_fail);
94+
assertTrue(checkTestFail(slow_fail));
95+
96+
assertTestNotSkip(slow_fail);
97+
assertTrue(checkTestNotSkip(slow_fail));
98+
99+
assertTestNotExpire(slow_fail);
100+
assertTrue(checkTestNotExpire(slow_fail));
101+
102+
pass();
103+
}
104+
}
105+
106+
testing(slow_skip_monitor) {
107+
unsigned long now = millis();
108+
if (now < 1000) {
109+
assertTestNotDone(slow_skip);
110+
assertTrue(checkTestNotDone(slow_skip));
111+
112+
assertTestNotPass(slow_skip);
113+
assertTrue(checkTestNotPass(slow_skip));
114+
115+
assertTestNotFail(slow_skip);
116+
assertTrue(checkTestNotFail(slow_skip));
117+
118+
assertTestNotSkip(slow_skip);
119+
assertTrue(checkTestNotSkip(slow_skip));
120+
121+
assertTestNotExpire(slow_skip);
122+
assertTrue(checkTestNotExpire(slow_skip));
123+
}
124+
if (now > 2000) {
125+
assertTestDone(slow_skip);
126+
assertTrue(checkTestDone(slow_skip));
127+
128+
assertTestNotPass(slow_skip);
129+
assertTrue(checkTestNotPass(slow_skip));
130+
131+
assertTestNotFail(slow_skip);
132+
assertTrue(checkTestNotFail(slow_skip));
133+
134+
assertTestSkip(slow_skip);
135+
assertTrue(checkTestSkip(slow_skip));
136+
137+
assertTestNotExpire(slow_skip);
138+
assertTrue(checkTestNotExpire(slow_skip));
139+
140+
pass();
141+
}
142+
}
143+
144+
#if USE_AUNIT == 1
145+
testing(slow_expire_monitor) {
146+
unsigned long now = millis();
147+
if (now < 1000) {
148+
assertTestNotDone(slow_expire);
149+
assertTrue(checkTestNotDone(slow_expire));
150+
151+
assertTestNotPass(slow_expire);
152+
assertTrue(checkTestNotPass(slow_expire));
153+
154+
assertTestNotFail(slow_expire);
155+
assertTrue(checkTestNotFail(slow_expire));
156+
157+
assertTestNotSkip(slow_expire);
158+
assertTrue(checkTestNotSkip(slow_expire));
159+
160+
assertTestNotExpire(slow_expire);
161+
assertTrue(checkTestNotExpire(slow_expire));
162+
}
163+
if (now > 2000) {
164+
assertTestDone(slow_expire);
165+
assertTrue(checkTestDone(slow_expire));
166+
167+
assertTestNotPass(slow_expire);
168+
assertTrue(checkTestNotPass(slow_expire));
169+
170+
assertTestNotFail(slow_expire);
171+
assertTrue(checkTestNotFail(slow_expire));
172+
173+
assertTestNotSkip(slow_expire);
174+
assertTrue(checkTestNotSkip(slow_expire));
175+
176+
assertTestExpire(slow_expire);
177+
assertTrue(checkTestExpire(slow_expire));
178+
179+
pass();
180+
}
181+
}
182+
#endif
183+
184+
void setup() {
185+
Serial.begin(74880); // 74880 is default for some ESP8266 boards
186+
while(!Serial); // for the Arduino Leonardo/Micro only
187+
}
188+
189+
void loop() {
190+
#if USE_AUNIT == 1
191+
// Should get the following summary output:
192+
// TestRunner summary:
193+
// 5 passed, 1 failed, 1 skipped, 1 timed out, out of 8 test(s).
194+
//
195+
//TestRunner::setVerbosity(Verbosity::kAll);
196+
TestRunner::run();
197+
#else
198+
// Should get the following summary output:
199+
// Test summary: 4 passed, 1 failed, and 1 skipped, out of 6 test(s).
200+
Test::run();
201+
#endif
202+
}

0 commit comments

Comments
 (0)