Skip to content
This repository has been archived by the owner on Sep 27, 2021. It is now read-only.

How To: Unit Testing

Tyler Gamvrelis edited this page Oct 30, 2018 · 5 revisions

The following steps will ensure that code can be thoroughly tested independent of the hardware it will be running on.

Adding Files to the Code Base

  1. Add source files that do not depend on any board-specific hardware to Common/component/. For example, Common/component/NewModule/NewInterface.cpp
  2. Write a test driver file using the GoogleTest/GoogleMock framework add it under Common/test. This file name will be the name of the module or class followed by "_test", e.g. "NewModule_test.cpp" and "NewInterface_test.cpp". Sometimes it is easier to test class-by-class, while other times it is only necessary to test the module. This depends on the complexity of the module and it is left up to the programmer's discretion to do what they think is clear and easy to maintain
  3. With RobotTest open in Eclipse, navigate to the new source and test files within the linked resources "Common" and uncheck "Exclude resource from build" under Properties->C/C++ Build->Settings for all relevant configurations
  4. Run the unit tests under all configurations (e.g. Test_F4 and Test_F7) to ensure the new code is portable to all supported hardware options

Unit Testing

TODO: tutorial on writing unit tests & brief overview of test-driven development. Also go over how to fake calls to the hardware to test data processing algorithms