Skip to content

Commit

Permalink
Merge pull request #22 from bxparks/develop
Browse files Browse the repository at this point in the history
merge 0.4.2
  • Loading branch information
bxparks authored Apr 10, 2018
2 parents 4f6a241 + 694d92e commit 0d12224
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 112 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

* 0.4.2 (2018-04-10)
* Fix FSM for excluded tests so that they bypass setup() and teardown().
* 0.4.1 (2018-04-06)
* Add support for `Test::teardown()` for use in test fixtures.
* Add 2-argument versions of `TestRunner::include()` and
Expand Down
99 changes: 70 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
A unit testing framework for Arduino platforms inspired by ArduinoUnit and
Google Test.

Version: 0.4.1 (2018-04-06)
Version: 0.4.2 (2018-04-10)

## Summary

Expand Down Expand Up @@ -89,7 +89,10 @@ Here are the features in AUnit which are not available in ArduinoUnit:
* `checkTestXxxF()`
* `externTestF()`
* `externTestingF()`
* AUnit works on the ESP8266 platform.
* AUnit supports the `teardown()` method to clean up test fixtures after
the `setup()` method.
* AUnit is tested on the AVR (8-bit), Teensy ARM (32-bit) , and ESP8266 (32-bit)
Arduino platforms.
* Test filters (`TestRunner::include()` and `TestRunner::exclude()`) support the
same 2 arguments versions corresponding to `testF()` and `testingF()`

Expand Down Expand Up @@ -196,11 +199,11 @@ Here is a rough outline of an AUnit unit test sketch:
using namespace aunit;
test(example_test) {
... assertXxx() ...
...assertXxx()...
}
testing(looping_test) {
... code ...
...code...
if (...) {
pass();
} else if (...) {
Expand All @@ -215,17 +218,17 @@ class CustomTestOnce: public TestOnce {
// optional
virtual void setup() override {
TestOnce::setup();
...set up code...
...setup code...
}
// optional
virtual void teardown() override {
...tear down code...
...teardown code...
TestOnce::teardown();
}
void assertBigStuff() {
... higher level assertions ...
...higher level assertions...
}
};
Expand All @@ -240,12 +243,12 @@ class CustomTestAgain: public TestAgain {
// optional
virtual void setup() override {
TestAgain::setup();
...set up code...
...setup code...
}
// optional
virtual void teardown() override {
...tear down code...
...teardown code...
TestOnce::teardown();
}
Expand Down Expand Up @@ -408,30 +411,41 @@ To create a test fixture:
1. Derives a new class from either `TestOnce` (if you want to run the test just
once), or `TestAgain` (if you want to run the test repeatedly).
1. Add any data objects inside the class.
1. Add a `void setup() {...}` method to perform any common
1. Optionally add a `virtual void setup() {...}` method to perform any common
initialization code. Be sure to call the parent's `setup()` method in the
first line to chain any `setup()` methods defined by the parents. There may
*first* line to chain any `setup()` methods defined by the parents. There may
be multiple parent classes.
1. Optionally add a `virtual void teardown() {...}` method to perform any common
clean up code. Be sure to call the parent's `teardown()` method in the *last*
line to chain any `teardown()` methods defined by the parents. There may be
multiple parent classes.
1. Add any additional shared methods into this new class.

To define your tests, use the `testF()` macro like this:
```
class CustomTestOnce: public TestOnce {
protected:
// optional
virtual void setup() override {
TestOnce::setup(); // chain the parent's setup()
... setup code ...
TestOnce::setup();
...setup code...
}
// optional
virtual void teardown() override {
...teardown code...
TestOnce::teardown();
}
void assertCustomStuff() {
... common code ...
...common code...
}
int sharedValue;
};
testF(CustomTestOnce, calculate) {
... test code here ...
...test code here...
}
```
No constructor for `CustomTestOnce` needs to be defined.
Expand All @@ -447,20 +461,27 @@ To define a continuous test, use the `testingF()` macro like this:
```
class CustomTestAgain: public TestAgain {
protected:
// optional
virtual void setup() override {
TestOnce::setup(); // chain the parent's setup()
... setup code ...
TestAgain::setup();
...setup code...
}
// optional
virtual void teardown() override {
...teardown code...
TestAgain::teardown();
}
void assertCustomStuff() {
... common code ...
...common code...
}
int sharedValue;
};
testingF(CustomTestAgain, calculate) {
... test code here ...
...test code here...
}
```

Expand All @@ -471,8 +492,9 @@ Similarly, the `testingF()` macro creates a subclass named
See `examples/fixtures/fixtures.ino` to see a working example of the `testF()`
macro.

***ArduinoUnit Compatibility***: _The `testF()` and `testingF()` macros
are available only in AUnit (and Google Test), not ArduinoUnit._
***ArduinoUnit Compatibility***: _The `testF()` and `testingF()` macros,
and the `teardown()` virtual method are available only in AUnit (and Google
Test), not ArduinoUnit._

### Early Return and Delayed Assertions

Expand All @@ -491,9 +513,16 @@ then `doStuff()` inside `testF()` will execute:
```
class CustomTestOnce: public TestOnce {
protected:
// optional
virtual void setup() override {
TestOnce::setup(); // chain the parent's setup()
... setup code ...
TestOnce::setup();
...setup code...
}
// optional
virtual void teardown() override {
...teardown code...
TestOnce::teardown();
}
void assertCustomStuff() {
Expand Down Expand Up @@ -610,6 +639,7 @@ available in AUnit._
The following methods are defined at the `Test` base class level:

* `setup()`
* `teardown()`

The `TestOnce` class defines:
* `once()`
Expand All @@ -618,8 +648,9 @@ The `TestAgain` class defines:
* `again()`

***ArduinoUnit Compatibility***: _These are functionally the same as ArduinoUnit
except with different class names. Instead of `Test` use `TestAgain`, Instead
of `Test::loop`, use `TestAgain::again()`._
except with different class names. Instead of `Test` use `TestAgain`. Instead
of `Test::loop` use `TestAgain::again()`. ArduinoUnit does not support a
`teardown()` method._

### Running the Tests

Expand Down Expand Up @@ -655,7 +686,6 @@ We can `exclude()` or `include()` test cases using a pattern match:
* `TestRunner::include(pattern)`
* `TestRunner::include(testClass, pattern)`


These methods are called from the global `setup()` method:

```
Expand All @@ -668,6 +698,10 @@ void setup() {
}
```

Excluded tests bypass their `setup()` and `teardown()` methods and terminate
immidiately. For the purposes of reporting, however, excluded tests are
counted as "skipped".

The 2-argument versions of `include()` and `exclude()` correspond to the
2 arguments of `testF()` and `testingF()`.

Expand Down Expand Up @@ -905,9 +939,16 @@ messages for successful assertions (with a
```
class CustomTestOnce: public TestOnce {
protected:
// optional
virtual void setup() override {
TestOnce::setup(); // chain the parent's setup()
... setup code ...
TestOnce::setup();
...setup code...
}
// optional
virtual void teardown() override {
...teardown code...
TestOnce::teardown();
}
void assertCustomStuff() {
Expand All @@ -926,7 +967,7 @@ class CustomTestOnce: public TestOnce {
testF(CustomTestOnce, calculate) {
enableVerbosity(Verbosity::kAssertionPassed);
... test code here ...
...test code here...
assertCustomStuff();
}
```
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=AUnit
version=0.4.1
version=0.4.2
author=Brian T. Park <brian@xparks.net>
maintainer=Brian T. Park <brian@xparks.net>
sentence=A unit testing framework for Arduino platforms inspired by ArduinoUnit and Google Test.
Expand Down
2 changes: 1 addition & 1 deletion src/AUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ SOFTWARE.
#include "aunit/TestMacro.h"

// Version format: xxyyzz == "xx.yy.zz"
#define AUNIT_VERSION 000401
#define AUNIT_VERSION 000402

#endif
5 changes: 3 additions & 2 deletions src/aunit/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Test** Test::getRoot() {
}

Test::Test():
mStatus(kStatusNew),
mLifeCycle(kLifeCycleNew),
mStatus(kStatusUnknown),
mVerbosity(Verbosity::kNone),
mNext(nullptr) {
}
Expand All @@ -56,7 +57,7 @@ Test::Test():
// status as kStatusSetup to allow testing() test cases to continue.
void Test::setPassOrFail(bool ok) {
if (!ok) {
mStatus = kStatusFailed;
setStatus(kStatusFailed);
}
}

Expand Down
Loading

0 comments on commit 0d12224

Please sign in to comment.