-
Notifications
You must be signed in to change notification settings - Fork 76
Testing
We use Google's GTest framework for C++ unit tests. It is a great framework that is very easy to use, and all modules should have unit tests written for them. We will be using the PyUnit (unittest) module, which is in the Python standard library for testing Python code.
To maintain consistency in our codebase, you should create a test
folder in each module's directory, which contains all that modules test files. After writing the test (look at gamestate, balltrack, or vision for examples) you need to add the test to that modules CMakeList. There is a simple macro nbites_add_test()
that will create an executable and link the specified libraries. All of this should be done only while OFFLINE, not when compiling for a robot, so this should all take place in an if( OFFLINE )
block.
-
First declare the
if ( OFFLINE )
statement at the end of the current CMakeList if there are not currently any tests in the directory. Declare anendif ( OFFLINE )
statement underneath, all the following code should be indented and between theif
andendif
. -
Use
nbites_add_test()
to add the test. The first argument should be the name of the executable you want to create (for example this would beCommTests
), the second is the cpp test file, i.e. the test you wrote. This is without thetest/
directory prefix, as the macro assumes to look there already. Any additional arguments to the macro will be linked with the executable. You should link the module you are testing, but beyond that you don't have to have much.
To use the tests you need to compile the codebase to work on your computer, which you designate by using make straight
instead of make cross
. Once the file is configured, run make
to compile all the code, and then run make test
to run all of the tests in the system. You will get a summary at the end of all of the tests to tell you if anything failed.
This is a crucial step for our team to take as good testing means good and easily managed code. PLEASE start using tests right. There is no excuse to saying something works before you've written a test and it has passed. The easiest way to do this is look at an example while you're going through the steps, and as always, edit the wiki as things change and as you use it to make it clearer for the next one.