AUnit
1.7.1
Unit testing framework for Arduino platforms inspired by ArduinoUnit and Google Test.
|
This directory contains fake versions of some Arduino classes for the purposes of unit testing. These header files are not included automatically by the #include <AUnit.h>
preprocessor directive. The various fake classes must be included manually just after the <AUnit.h>
is included. The fake classes live in the aunit::fake
namespace.
The FakePrint
class is an implementation of the Print class which is the base class of the HardwareSerial and other output classes. The Serial
global object is an instance of the HardwareSerial
class. If a user-defined class or method is defined to use an instance of the Print
object, instead of hardcoding a dependency to the Serial
instance, then an instance of the FakePrint
class can be substituted and used to write unit tests for the user-defined class or method.
Let's say the user-defined class is called Greeter
and a method called greet()
prints something out to Serial
:
If we want to verify that the Greeter::greet()
method prints what is expected, we inject an instance of FakePrint
(instead of Serial
) in a test called GreeterTest.ino
: