Hardware Reference
In-Depth Information
The Arduino Test Suite comes with a test skeleton. This is the smallest test possible, which makes it a good starter
sketch. This is shown in Listing 13-2.
Listing 13-2. Minimal Test Sketch
#include <ArduinoTestSuite.h>
//************************************************************************
void setup()
{
ATS_begin("Arduino", "My bare bones tests");
testTrue();
ATS_end();
}
void testTrue()
{
boolean result;
result = true;
ATS_PrintTestStatus("My bare bones test", result);
}
void loop()
{
}
Listing 13-2 shows the standard sketch structure. The tests are placed in setup() , so they are only run once.
They can also be placed in loop() , which would run them multiple times; this can be useful if you are testing
time and repetition issues. You can put your tests in loop() as long as you include while(1){} after the tests are
complete.
In order to access the tests, you need to import the Arduino Test Suite with the #include <ArduinoTestSuite.h>
line. Remember that tests need a name and an expected result. In this case, we create a Boolean variable called result .
Our goal is to show that the result is TRUE . Here's where we begin:
ATS_begin("Arduino", "My bare bones tests");
This sets up the test suite run and initializes the starting conditions. Then you can do anything you need to,
including setting up variables, calling libraries, and calling any function that you are testing. The test result is set as an
outcome of the code, and the status is printed to the serial port:
ATS_PrintTestStatus("My bare bones test", result);
Finally, once ATS_end() is called, the test is over and you can clean up.
An even better option for testing is to place each test in its own function. That way, it is more clearly isolated from
other tests and side effects are largely avoided.
The results of the tests appear in the serial monitor format shown in Listing 13-3.
Listing 13-3. Minimal Test Sketch Results
info.MANUFACTURER = Arduino
info.CPU-NAME = ATmega328P
info.GCC-Version = 4.3.2
info.AVR-LibC-Ver = 1.6.4
info.Compiled-date = Oct 20 2010
 
Search WWH ::




Custom Search