fluxnet/ONEFlux

Unit testing C code using a framework

Closed this issue · 0 comments

ma595 commented

ONEFlux does not have any C unit testing in place (apart from on-the-fly checks). Writing tests of the pre-existing 'C' code is a large engineering task but a good (and perhaps necessary) first step is to write tests for code that is expected to change in the near term.

Testing ONEFlux's C code can be done by writing our own testing macros or by using a testing framework. Here we suggest adopting a framework. There are a few advantages:

  • They are well tested.
  • Provide advanced features like the ability to run subsets of tests. And many more...
  • Coverage support

Unlike python, where 'pytest' is really the only choice, in C the decision is less clear cut. There are many:

  • Check
  • gtest
  • cmocka
  • utest
  • kyua + atf

The aim is to demonstrate the adoption of a C testing framework by writing a few simple tests of a step in the ONEFlux pipeline. meteo_proc.c is a good candidate for testing.