Menu

Additional tools

pogn

Opmock comes currently with a simple helper script to generate test files for you.

Generating your test suite automatically

If you've chosen to use the unit testing framework that comes with opmock, then every time you add a new test, you need to:

  • Modify the C or C++ file where the test implementation is located
  • Modify the header file where the test signature is defined
  • Modify the main file to register the new test

It is somewhat tedious to maintain all these files, and one can easily forget to register a test. Opmock provides a very simple utility script in the scripts folder:
refresh_tests.sh.

This script will:

  • Read a list of C and/or cpp test files
  • Parse each file to find tests. To find your tests, they must follow a specific signature, which is : void test_name_of_the_test(). Note that you can have blank spaces or tab before the void, this will work as well.
  • Generate a header file matching the test. If the test file is named “mytest1.c” then the header file will be named “mytest1.h”. You should include this header in your test file. You can have several test files : a header will be generated for each of them.
  • Generate a main.c file registering and running all your tests.

Calling the script is simple:
refresh_tests.sh fizzbuzz_test.c fizzbuzz_test2.c

Will generate 2 header files and a main.c file. You may have to rename the main.c to main.cpp if you have link time errors with a mix of C and CPP files.

There's a fully working example, including Makefile rules, in the samples/test_gen folder of the Opmock distribution.

Accepted extensions for C test files are:
.c, .C, and will result in .h files.
Accepted extensions for C++ test files are:
.cc; .cpp, .c++, .CC, and will result in .hpp files.


Related

Wiki: Home

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.