#include <ArduinoUnit.h>
Public Member Functions | |
void | pass () |
void | fail () |
void | skip () |
virtual void | setup () |
virtual void | loop ()=0 |
Test (const __FlashStringHelper *_name, uint8_t _verbosity=TEST_VERBOSITY_TESTS_ALL|TEST_VERBOSITY_ASSERTIONS_FAILED) | |
Test (const char *_name, uint8_t _verbosity=TEST_VERBOSITY_TESTS_ALL|TEST_VERBOSITY_ASSERTIONS_FAILED) | |
Static Public Member Functions | |
static uint16_t | getCurrentPassed () |
static uint16_t | getCurrentSkipped () |
static uint16_t | getCurrentFailed () |
static uint16_t | getCurrentCount () |
static void | include (const char *pattern) |
static void | exclude (const char *pattern) |
static void | run () |
template<typename T > | |
static bool | assertion (const __FlashStringHelper *file, uint16_t line, const __FlashStringHelper *lhss, const T &lhs, const __FlashStringHelper *ops, bool(*op)(const T &lhs, const T &rhs), const __FlashStringHelper *rhss, const T &rhs) |
Public Attributes | |
uint8_t | state |
String | name |
uint8_t | verbosity |
Static Public Attributes | |
static uint8_t | max_verbosity = TEST_VERBOSITY_ALL |
static uint8_t | min_verbosity = TEST_VERBOSITY_TESTS_SUMMARY |
static const uint8_t | UNSETUP = 0 |
static const uint8_t | LOOPING = 1 |
static const uint8_t | DONE_SKIP = 2 |
static const uint8_t | DONE_PASS = 3 |
static const uint8_t | DONE_FAIL = 4 |
static Print * | out = &Serial |
static Test * | current = 0 |
There are two convenience macros for extending this class and implement a one-step test (test macro), or a multi-step test (testing macro).
One shot (first loop()) test
test(me_once) { int x=1,y=2; assertNotEqual(x,y); }
Continuous (every loop() until pass(), fail(), or skip()) test
testing(me_often) { assertEqual(digitalRead(errorPin),LOW); }
Roll-your-own test:
class MyTest : public Test { public: MyTest(const char *name) : Test(name) {} {
can set verbosity here. } void setup() { can set verbosity here. call call pass(), fail(), or skip() can make assertions } void loop() { can set verbosity here. call call pass(), fail(), or skip() can make assertions } };
void setup() { all tests are included by default Test::exclude("*_skip"); if (no_slow_tests) Test::exclude("*_slow"); if (all_crypto_tests) { Test::include("crypto_*"); Test::exclude("crypto_*_skip"); } }
void loop() { Test::run(); }
Variables you might want to adjust:
static Print* Test::out
&Serial
This affects the output of all tests
uint8_t verbosity
– defaults to
TEST_VERBOSITY_ASSERTIONS_FAILED|TEST_VERBOSITY_TESTS_ALL
– to keep code small, reporting code that is not set in
TEST_MAX_VERBOSITY
is removed, so setting verbosity bits outside this mask has no effect. The default mask is to have all output available, and the only reason to change this is to save some code space.
|
static |
exclude (skip) currently included tests that match some wildcard (*) pattern like,
"my_broken_test", "*_skip", "*", "io_*", etc.
This should be done inside your setup() function.
void Test::fail | ( | ) |
Set state to DONE_FAIL. This does not exit the code early. But after the loop() terminates, the test will be resolved and removed from the list of active tests.
|
static |
|
pure virtual |
Run a test. Test::loop() will be called on each Test::run() until a pass(), fail() or skip().
Implemented in TestOnce.
void Test::pass | ( | ) |
Set state to DONE_PASS. This does not exit the code early. But after the loop() terminates, the test will be resolved and removed from the list of active tests.
|
static |
Simple usage:
void setup() { Serial.begin(9600); } void loop() { Test::run(); }
Complex usage:
void setup() { Test::exclude("*"); // exclude everything Test::include("io_*"); // but include io_* tests Test::exclude("io_*_lcd"); // except io_*_lcd tests Test::include("crypto_*_aes128"); // and use all crypto_*_aes128 tests }
void loop() { Test::run(); }
|
virtual |
Setup a test. This is an nop {} definition by default, but for some more general cases it will be called once from before continuously calling Test::loop(). You can skip(), pass(), fail(), set verbosities, or make assertions here.
void Test::skip | ( | ) |
Set state to DONE_SKIP. This does not exit the code early. But after the loop() terminates, the test will be resolved and removed from the list of active tests.
|
static |
The current active test (=0 if none are active). Asserts are allowed outside of tests, but just return if fail and potentially (according to min_verbosity and max_verbosity) print a message to the Test::out stream.
|
static |
State of a failed test.
|
static |
State of a passed test.
|
static |
State of a test that will be counted as skipped. This can be done any time before resolving the test some other way, but should mean some small amount of steps to determine that no actual testing was done.
|
static |
State of a test while actively in loop(). Tests are resolved by changing state one of the DONE_ states.
|
static |
After the compile-time-mask TEST_MAX_VERBOSITY, this is a global run-time-mask of what output should be generated.
|
static |
After the compile-time-mask TEST_MAX_VERBOSITY, and the global (static) run-time-mask Test::max_verbosity of what output can be generated, this is a global (static) run-time-mask of what output should be generated.
String Test::name |
the name of this test
|
static |
/brief Output stream for all tests. The default value of this is ``` Test::out = ``` This places the output on the main serial port. The library does not set the baud rate, so you must do so in your setup().
To redirect all output to some other stream, say the Serial3 device of the arduino mega, use
Serial3.begin(19200L); Test::out = &Serial3;
in your setup().
uint8_t Test::state |
The current state of this test. It is one of:
UNSETUP, LOOPING, DONE_PASS, DONE_FAIL, DONE_SKIP
|
static |
uint8_t Test::verbosity |
Per-test verbosity defaults to TEST_VERBOSITY_TESTS_ALL|TEST_VERBOSITY_ASSERTS_FAILED, but note that the compile-time constant TEST_VERBOSITY_MAX and run-time global (static) values Test::max_verbosity and Test::min_verbosity also effect the verbosity of a test. According to the following rules:
output = false; if (TEST_MAX_VERBOSITY bit is set (output KIND exists)) { if (all-test Test::max_verbosity bit is set (output KIND allowed)) { if (all-test Test:min_verbosity bit is set (output KIND required)) { output = true; } else if (per-test Test::verbosity bit is set (output KIND use)) { output = true; } } }
if (output) { OUTPUT to Test::out }