I have an application written in C++, configured with CMake, tested using Catch2, the tests are invoked through CTest.
I have a fairly large list of files that each contain captures of messages that have caused an issue in my application in the past. I currently have a single test that runs through each of these files serially using code that looks approximately like:
TEST_CASE("server type regressions", "[server type]") {
auto const state = do_some_setup();
for (auto const path : files_to_test()) {
INFO(path);
auto parser = state.make_parser(path);
for (auto const message : parser) {
INFO(message);
handle(message);
}
}
}
The message handler has a bunch of internal consistency checks, so when this test fails, it typically does so by throwing an exception.
Is it possible to improve this solution to get / keep the following:
- Run the initial
do_some_setup
once for all of the tests, but then run the test for each file in parallel.do_some_setup
is fairly slow, and I have enough files relative to the number of cores that I wouldn't want to have to do setup per file. It would also be acceptable to rundo_some_setup
more than once, as long as it's better than O(n) in the number of files. - Run the regression test on all the files, even when an earlier file fails. I know I could do this with a
try
+catch
and manually setting abool has_failed
on any failure, but I'd prefer if there were some built-in way to do this? - Be able to specify the file name when invoking tests, so that I can manually run just the test for a single file
- Automatically detect the set of files. I would prefer not having to change to a solution where I need to add test files to the test file directory and also update some other location that lists all of the files I'm testing to manually shard them
I'm willing to write some CMake to manage this, pass some special flags to CTest or Catch2, or change to a different unit testing framework.