Closed evanmayer closed 2 years ago
Pros:
Cons:
Pros:
libboost-test-dev
Cons:
#include
s many others (think about it - a single header would be a nightmare to maintain)Pros:
.h
, 1, .c
for unit testsCons:
Pros:
Cons:
Pros:
Cons:
Pros:
.c
, 5 .h
Cons:
Based on this, I recommend cmocka. Cpputest would also probably work.
cmocka example code in the SW primer repo.
Building tests against it was simple, and would be even easier to use if we used the included CMake files to install it in the dev environment, rather than building against it as a static library as I did in the example. This is the preferred method of using it; right now the cmocka unit tests are mixed in with mine because of the lazy CMake I wrote.
It's even possible to build it in the Debian environment by relaxing the CMake version requirement to 3.0.0.
CTest output:
vagrant@debian-jessie:/git/TIM-software-primer/unittest_example_cmocka/build$ ctest
Test project /git/TIM-software-primer/unittest_example_cmocka/build
Start 1: add_example_test
1/7 Test #1: add_example_test ................. Passed 0.00 sec
Start 2: simple_test
2/7 Test #2: simple_test ...................... Passed 0.00 sec
Start 3: allocate_module_test
3/7 Test #3: allocate_module_test ............. Passed 0.00 sec
Start 4: assert_macro_test
4/7 Test #4: assert_macro_test ................ Passed 0.00 sec
Start 5: assert_module_test
5/7 Test #5: assert_module_test ............... Passed 0.00 sec
Start 6: waiter_test_wrap
6/7 Test #6: waiter_test_wrap ................. Passed 0.00 sec
Start 7: test_uptime
7/7 Test #7: test_uptime ...................... Passed 0.00 sec
100% tests passed, 0 tests failed out of 7
Total Test time (real) = 0.04 sec
Running the test executable manually:
vagrant@debian-jessie:/git/TIM-software-primer/unittest_example_cmocka/build/src$ ./add_example_test_exec
[==========] Running 1 test(s).
[ RUN ] test_AddOnePlusOne
[ OK ] test_AddOnePlusOne
[==========] 1 test(s) run.
[ PASSED ] 1 test(s).
However, we could also go the route of using a C unit testing framework that does only unit tests (Unity, Check), and tack on a mocking framework like FFF if/when we need it.
Nick has rewritten any tests he wrote in Unity using cmocka (thanks Nick!) so we'll go forward with that.
Task
Pick a unit test framework for the project and describe why it was chosen.
Acceptance
Comment on this issue to document process of choosing.
Provide a sample unit test project.
Details