Skip to content

Commit 6d4b9a2

Browse files
authored
Merge pull request #5 from bxparks/develop
v0.3.1 - Add support for Verbosity::kTestExpired
2 parents b042c64 + 340242a commit 6d4b9a2

File tree

17 files changed

+298
-198
lines changed

17 files changed

+298
-198
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.1 (2018-03-20)
4+
* Add support for Verbosity::kTestExpired.
5+
* Clean up code in examples/ directory and add documentation in README.md.
36
* v0.3.0 (2018-03-19)
47
* Implement all remaining macros from ArduinoUnit:
58
assertTestXxx(), checkTestXxx(), externTest(), externTesting().

README.md

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# AUnit - Unit Testing Framework for Arduino Platforms
22

3-
Version: v0.3.0 (2018-03-19)
3+
Version: 0.3.1 (2018-03-20)
44

55
## Summary
66

@@ -23,7 +23,7 @@ AUnit was created to solve 2 problems with ArduinoUnit:
2323
[ArduinoUni#54](https://github.com/mmurdoch/arduinounit/issues/54)).
2424

2525
In contrast:
26-
* AUnit consumes as much as 66% *less* flash memory than ArduinoUnit on the
26+
* AUnit consumes as much as 65% *less* flash memory than ArduinoUnit on the
2727
AVR platform. On Teensy-ARM, the savings can be as much as 30%.
2828
* AUnit has been tested on AVR, Teensy-ARM and ESP8266.
2929

@@ -98,6 +98,21 @@ pick up the new library.
9898
In this section, information about differences between AUnit and ArduinoUnit
9999
will appear in a note marked by ***ArduinoUnit Compatibility***.
100100

101+
### Examples
102+
103+
The `examples/` directory has a number of examples:
104+
105+
* `advanced` - how to subclass `Test` and `TestOnce` manually
106+
* `basic` - using the `test()` macro
107+
* `continuous` - using the `testing()` macro
108+
* `filter` - how to filter tests using `TestRunner::include()` and
109+
`TestRunner::exclude()`
110+
* `meta_asserts` - how to use `assertTestXxx()` and `checkTestXxx`
111+
112+
In the `tests/` directory:
113+
114+
* `AUnitTest` - the unit test for `AUnit` itself has a large number of examples
115+
101116
### Header and Namespace
102117

103118
To prevent name clashes with other libraries and code, all classes in the AUnit
@@ -121,7 +136,7 @@ in the global namespace, so it is usually not necessary to import the entire
121136
`aunit` namespace.
122137

123138
***ArduinoUnit Compatibility***: _I have found that the following macros are
124-
useful during the transition:_
139+
useful during the transition from ArduinoUnit to AUnit_
125140
```
126141
#define USE_AUNIT 1
127142
@@ -356,7 +371,10 @@ returns `false`, and prints assertion messages that look like this:
356371
Assertion passed: Test slow_pass is done, file AUnitTest.ino, line 366.
357372
Assertion passed: Test slow_pass is not failed, file AUnitTest.ino, line 372.
358373
Assertion passed: Test slow_skip is skipped, file AUnitTest.ino, line 448.
374+
Assertion passed: Test slow_skip is not timed out, file AUnitTest.ino, line 451.
359375
```
376+
(The human readable version of being `expired` will always be `timed out` or
377+
`not timed out` on the `Serial` output.)
360378

361379
The following macros define `extern` references to test case objects which live
362380
in other `.cpp` files. These are required for the above meta assertions if the
@@ -509,21 +527,23 @@ The names of the bit field flags are different from ArduinoUnit to avoid name
509527
collisions with other `#define` macros which have global scope. AUnit uses
510528
static constants of the `Verbosity` utility class:
511529

512-
* `Verbosity::kTestRunSummary`
513-
* `Verbosity::kTestFailed`
530+
* `Verbosity::kAssertionPassed`
531+
* `Verbosity::kAssertionFailed`
514532
* `Verbosity::kTestPassed`
533+
* `Verbosity::kTestFailed`
515534
* `Verbosity::kTestSkipped`
535+
* `Verbosity::kTestExpired`
536+
* `Verbosity::kTestRunSummary`
537+
* `Verbosity::kAssertionAll` - enables all assert messages
516538
* `Verbosity::kTestAll`
517-
* `Verbosity::kAssertionFailed`
518-
* `Verbosity::kAssertionPassed`
519-
* `Verbosity::kAssertionAll`
520-
* `Verbosity::kDefault`, equivalent to setting the following
521-
* `(Verbosity::kAssertionFailed | Verbosity::kTestAll)`
539+
* same as `(kTestPassed | kTestFailed | kTestSkipped | kTestExpired)`
540+
* `Verbosity::kDefault`
541+
* same as `(kAssertionFailed | kTestAll | kTestRunSummary )`
522542
* `Verbosity::kAll` - enables all messages
523543
* `Verbosity::kNone` - disables all messages
524544

525545
***ArduinoUnit Compatibility***:
526-
_The following ArduinoUnit variables do not exist:_`
546+
_The following ArduinoUnit variables do not exist:_
527547
* `Test::verbosity`
528548
* `Test::min_verbosity`
529549
* `Test::max_verbosity`
@@ -543,6 +563,7 @@ The bit field constants have slightly different names:_
543563
* `TEST_VERBOSITY_ALL` -> `Verbosity::kAll`
544564
* `TEST_VERBOSITY_NONE` -> `Verbosity::kNone`
545565
* {no equivalent} <- `Verbosity::kDefault`
566+
* {no equivalent} <- `Verbosity::kTestExpired`
546567

547568
### Line Number Mismatch
548569

@@ -648,7 +669,7 @@ A timeout value of `0` means an infinite timeout, which means that the
648669

649670
## Benchmarks
650671

651-
AUnit consumes as much as 66% less flash memory than ArduinoUnit on an AVR
672+
AUnit consumes as much as 65% less flash memory than ArduinoUnit on an AVR
652673
platform (e.g. Arduino UNO, Nano), and 30% less flash on the Teensy-ARM platform
653674
(e.g. Teensy LC ). Here are the resource consumption (flash and static) numbers
654675
from an actual unit test sketch containing 26 test cases using 331 `assertXxx()`
@@ -657,24 +678,24 @@ microcontrollers:
657678
```
658679
Platform (resource) | Max | ArduinoUnit | AUnit |
659680
---------------------------+---------+-------------+-------------|
660-
Arduino Nano (flash) | 30720 | 54038 | 18666 |
681+
Arduino Nano (flash) | 30720 | 54038 | 18818 |
661682
Arduino Nano (static) | 2048 | 1061 | 918 |
662683
---------------------------+---------+-------------+-------------|
663-
Teensy LC (flash) | 63488 | 36196 | 25228 |
684+
Teensy LC (flash) | 63488 | 36196 | 25240 |
664685
Teensy LC (static) | 8192 | 2980 | 2780 |
665686
---------------------------+---------+-------------+-------------|
666-
Teensy 3.2 (flash) | 262144 | 51236 | 36300 |
687+
Teensy 3.2 (flash) | 262144 | 51236 | 36236 |
667688
Teensy 3.2 (static) | 65536 | 5328 | 5236 |
668689
---------------------------+---------+-------------+-------------|
669-
ESP8266 - ESP-12E (flash) | 1044464 | does not | 266748 |
690+
ESP8266 - ESP-12E (flash) | 1044464 | does not | 266796 |
670691
ESP8266 - ESP-12E (static) | 81920 | compile | 33128 |
671692
---------------------------+---------+-------------+-------------|
672-
ESP8266 - ESP-01 (flash) | 499696 | does not | 266748 |
693+
ESP8266 - ESP-01 (flash) | 499696 | does not | 266796 |
673694
ESP8266 - ESP-01 (static) | 47356 | compile | 33128 |
674695
---------------------------+---------+-------------+-------------|
675696
```
676697

677-
Not all unit test sketches will experience a savings of 66% of flash memory with
698+
Not all unit test sketches will experience a savings of 65% of flash memory with
678699
AUnit, but a savings of 30-50% seems to be common.
679700

680701
## Changelog

examples/advanced/advanced.ino

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#line 2 "advanced.ino"
22

3-
// Copied from:
3+
// Adapted from:
44
// https://github.com/mmurdoch/arduinounit/blob/master/examples/advanced/advanced.ino
55

66
#define USE_AUNIT 1
@@ -12,83 +12,78 @@ using namespace aunit;
1212
#include <ArduinoUnit.h>
1313
#endif
1414

15-
test(simple1)
16-
{
15+
test(simple1) {
1716
assertTrue(true);
1817
}
1918

20-
test(simple2)
21-
{
19+
test(simple2) {
2220
assertTrue(false);
2321
}
2422

25-
class MyTestOnce : public TestOnce
26-
{
27-
public:
28-
// constructor must name test
29-
30-
MyTestOnce(const char *name)
31-
: TestOnce(name)
32-
{
33-
// lightweight constructor, since
34-
// this test might be skipped.
35-
// you can adjust verbosity here
23+
class MyTestOnce: public TestOnce {
24+
public:
25+
MyTestOnce(const char *name):
26+
TestOnce(name) {
3627

3728
#if USE_AUNIT == 0
38-
verbosity = TEST_VERBOSITY_ALL;
29+
// lightweight constructor, since
30+
// this test might be skipped.
31+
// you can adjust verbosity here
32+
verbosity = TEST_VERBOSITY_ALL;
3933
#endif
40-
}
41-
42-
int n;
43-
44-
void setup()
45-
{
46-
n = random(6);
47-
if (n == 0) skip();
48-
}
49-
50-
void once()
51-
{
52-
for (int i=-n; i<=n; ++i) {
53-
for (int j=-n; j<=n; ++j) {
54-
assertEqual(i+j,j+i);
34+
}
35+
36+
virtual void setup() override {
37+
n = random(6);
38+
if (n == 0) skip();
39+
}
40+
41+
virtual void once() override {
42+
for (int i = -n; i <= n; ++i) {
43+
for (int j = -n; j <= n; ++j) {
44+
assertEqual(i+j, j+i);
45+
}
5546
}
5647
}
57-
}
48+
49+
private:
50+
int n;
5851
};
5952

6053
MyTestOnce myTestOnce1("myTestOnce1");
6154
MyTestOnce myTestOnce2("myTestOnce2");
6255
MyTestOnce myTestOnce3("myTestOnce3");
6356

64-
class MyTest : public Test
65-
{
66-
public:
67-
uint16_t when;
68-
MyTest(const char *name)
69-
: Test(name)
70-
{
71-
when = random(100,200);
72-
}
73-
74-
void loop()
75-
{
76-
if (millis() >= when)
77-
{
78-
assertLess(random(100),50L);
79-
pass(); // if assertion is ok
57+
class MyTest: public Test {
58+
public:
59+
MyTest(const char *name):
60+
Test(name) {
61+
when = random(100, 200);
8062
}
81-
}
63+
64+
virtual void loop() override {
65+
assertLess(getValue() ,50L);
66+
if (millis() >= when) {
67+
pass(); // if assertion is ok
68+
}
69+
}
70+
71+
private:
72+
long getValue() {
73+
return 20L;
74+
}
75+
76+
uint16_t when;
8277
};
8378

8479
MyTest myTest1("myTest1");
8580
MyTest myTest2("myTest2");
8681
MyTest myTest3("myTest3");
8782

88-
void setup()
89-
{
83+
void setup() {
9084
Serial.begin(74880); // 74880 is default for some ESP8266 boards
91-
while(!Serial); // for the Arduino Leonardo/Micro only
85+
while (!Serial); // for the Arduino Leonardo/Micro only
86+
delay(1000); // wait for stability on some boards to prevent garbage Serial
9287

9388
#if USE_AUNIT == 1
9489
TestRunner::setVerbosity(Verbosity::kAll);
@@ -100,11 +95,15 @@ void setup()
10095
#endif
10196
}
10297

103-
void loop()
104-
{
98+
void loop() {
10599
#if USE_AUNIT == 1
100+
// Should get:
101+
// TestRunner summary:
102+
// 5 passed, 1 failed, 2 skipped, 0 timed out, out of 8 test(s).
106103
TestRunner::run();
107104
#else
105+
// Should get:
106+
// Test summary: 5 passed, 1 failed, and 2 skipped, out of 8 test(s).
108107
Test::run();
109108
#endif
110109
}

examples/basic/basic.ino

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#line 2 "basic.ino"
22

3-
// Copied from:
3+
// Adapted from:
44
// https://github.com/mmurdoch/arduinounit/blob/master/examples/basic/basic.ino
55

66
#define USE_AUNIT 1
@@ -11,29 +11,31 @@
1111
#include <ArduinoUnit.h>
1212
#endif
1313

14-
test(correct)
15-
{
16-
int x=1;
17-
assertEqual(x,1);
14+
test(correct) {
15+
int x = 1;
16+
assertEqual(x, 1);
1817
}
1918

20-
test(incorrect)
21-
{
22-
int x=1;
23-
assertNotEqual(x,1);
19+
test(incorrect) {
20+
int x = 1;
21+
assertNotEqual(x, 1);
2422
}
2523

26-
void setup()
27-
{
24+
void setup() {
2825
Serial.begin(74880); // 74880 is default for some ESP8266 boards
2926
while(!Serial); // for the Arduino Leonardo/Micro only
27+
delay(1000); // wait for stability on some boards to prevent garbage Serial
3028
}
3129

32-
void loop()
33-
{
30+
void loop() {
3431
#if USE_AUNIT == 1
32+
// Should get:
33+
// TestRunner summary:
34+
// 1 passed, 1 failed, 0 skipped, 0 timed out, out of 2 test(s).
3535
aunit::TestRunner::run();
3636
#else
37+
// Should get:
38+
// Test summary: 1 passed, 1 failed, and 0 skipped, out of 2 test(s).
3739
Test::run();
3840
#endif
3941
}

0 commit comments

Comments
 (0)