Files

Unit Testing

Unit Test based on unity-library Unity.

  • Assertions (TEST_ASSERT and similar) are used when writing the test cases. See the reference for more information about assertions.

  • UNITY_BEGIN() and UNITY_END() macros allow Unity to count the number of tests which have passed or failed, and display the summary.

In addition to features of Unity, test registration feature of ESP-IDF is used. This feature works when unit test functions are declared using TEST_CASE macro. Such functions from all the object files in the program are automatically collected into a list, and run-time facilities are provided to run functions from this list.

Note testable components have a test subdirectory which is included in the test project When the main application project is compiled, tests are not included. Test project includes the tests by setting TEST_COMPONENTS variable in the project makefile.

Build and flash production code

  • Start an ESP-IDF-Terminal
  • Run idf.py -p PORT flash monitor in the current directory (unit_test).
  • Observe the output: a list of random numbers and their mean value. To exit the serial monitor, type Ctrl-].

Build and flash test code

  • Start an ESP-IDF-Terminal
  • Enter test directory (unit_test/test), and run idf.py -p PORT flash monitor. To exit the serial monitor, type Ctrl-].
  • Observe the output: results of test case execution.

This is the test menu, which is launched by unity_run_menu function in the test project. It allows running the tests in a few ways:

  • Run specific test by its index: type the number and press ENTER.
  • Run a group of tests with a certain tag: type the tag, including square brackets, and press ENTER.
  • nRu all tests except the ones with a certain tag: press !, then type the tag, including the square brackets, then press ENTER.
  • Run test with a specific name: type the name of the test, including quotes, and press ENTER.
  • Run all the tests: press * and then ENTER.