由Arduino Unit和Google Test所启发的Arduino平台的单位测试框架. 与EpoxyDuino一起用于连续建造.
A unit testing framework for Arduino platforms inspired by by
ArduinoUnit and Google
Test. AUnit is almost a drop-in
replacement of ArduinoUnit (v2.2) with some advantages. AUnit supports timeouts
and test fixtures. It sometimes consumes 50% less flash memory on the AVR
platform, and it has been tested to work on the AVR, SAMD21, STM32, ESP8266,
ESP32 and Teensy platforms. The assertion error messages were updated in v1.7 to
provide seamless integration with Unix tools like vim.
Originally, the AUnit tests were designed to run on the embedded controller itself which allows detection of architecture-specific problems. But the uploading, flashing, and execution process is often slow and flaky, causing the iteration cycle to take too much time. It is often more effective to execute the AUnit tests natively on a host machine (running Linux, MacOS, or FreeBSD) using the EpoxyDuino companion project. Once the unit tests are running on the Linux or MacOS host machine, they can be incorporated into a continuous integration system like Jenkins system or a cloud-based system like GitHub Actions.
Version: 1.7.1 (2023-06-15)
Changelog: CHANGELOG.md
AUnit was created to solve 3 problems with ArduinoUnit 2.2:
TEST_F() macro in Google Test.In contrast:
testF() and testingF() macros to use fixtures.The AUniter command line tools can compile the unit tests, upload them to Arduino boards attached to the serial ports of the local machine, and validate the output of the AUnit test runner. In addition, the AUniter script can be integrated into a Jenkins continuous integration service running on the local machine, and the unit tests can be monitored automatically.
Unit tests written using AUnit can often be compiled and executed natively on
Linux or MacOS using the
EpoxyDuino library. The output on
the Serial object is redirected to the stdout of the Unix host. This
provides another avenue for implementing continuous builds or integration.
For basic unit tests written using ArduinoUnit 2.2, only two changes are required to convert to AUnit:
#include -> #include Test::run() -> aunit::TestRunner::run()Most of the core macros are compatible between ArduinoUnit and AUnit:
test()testing()assertXxx()checkTestXxx()assertTestXxx()externTest()externTesting()AUnit also supports exclude and include filters:
TestRunner::exclude()TestRunner::include()Filters can be accessed through Command Line Flags on desktop machines using EpoxyDuino
The various assertion and test status messages can be enabled or disabled using
the Verbosity flags on per test basis:
enableVerbosity()disableVerbosity()Here are the features which have not been ported over from ArduinoUnit 2.2:
* wildcards in its exclude() and include()
methods. AUnit supports only a single * wildcard and it must occur at the
end if present.Here are the features in AUnit which are not available in ArduinoUnit 2.2:
testing() test cases from
running forever:TestRunner::setTimeout(seconds)Test::expire()assertTestExpire()assertTestNotExpire()checkTestExpire()checkTestNotExpire()assertStringCaseEqual()assertStringCaseNotEqual()assertNear()asssertNotNear()assertXxx() support both long long and unsigned long longtest() and testing() macros support both 1 and 2 argumentstest(testName) and test(suiteName, testName)testing(testName) and testing(suiteName, testName)testF()testingF()assertTestXxxF()checkTestXxxF()externTestF()externTestingF()passTestNow()failTestNow()skipTestNow()expireTestNow()teardown() method which mirrors the setup() method:teardown()testF() and testingF():TestRunner::include(testClass, name)TestRunner::exclude(testClass, name)String object.String if the calling code provides it.#include - terse messages use less flash memory#include - verbose messages use more flash memoryEvery feature of AUnit is unit tested using AUnit itself.
The latest stable release is available in the Arduino IDE Library Manager. Search for "unit test" or "AUnit", select "AUnit", then click the "Install" button.
The development version can be installed by cloning the
GitHub repository, checking out the
develop branch, then manually copying over the contents to the ./libraries
directory used by the Arduino IDE. (The result is a directory named
./libraries/AUnit.) See the Preferences menu for the location of the Arduino
sketch directory. The master branch contains the stable release.
Using either installation method, you may need to restart the Arduino IDE to pick up the new library.
The source files are organized as follows:
src/AUnit.h - main header filesrc/AUnitVerbose.h - verbose version of main header filesrc/aunit/ - all implementation filestests/ - unit tests written using AUnit itselfexamples/ - example sketchesThe examples/ directory has a number of examples:
TestRunner::include() and
TestRunner::exclude()assertTestXxx() and checkTestXxx()Test and TestOnce manuallytesting() macroexamples/ directory because of the Arduino IDE).In the tests/ directory, there are unit tests to test the AUnit framework
itself:
AUnit functionsextern*() macrosinclude() and exclude() filtersinclude() and exclude() filterssetup() and teardown() are called properly by the
finite state machinePerhaps the best way to see AUnit in action is through real life examples. All my libraries use AUnit for testing and for continuous integration through EpoxyDuino. Here are some of my libraries:
暂无开放 Issues,或尚未同步最近议题。