-
Notifications
You must be signed in to change notification settings - Fork 6
Introduction
So, you're looking for a unit testing framework to help you discover bugs and keep your (OpenFOAM-related) code's quality high enough? Well, that is hard to achieve, and this is my attempt at it! Enjoy!
Writing OpenFOAM code and hoping for the best is a very common practice in the OpenFOAM community. Well, testing code on specific OpenFOAM cases is more common, but it's basically the same thing.
The need for an easy-to use "harness suite" that doesn't make you waste 80% of your time on setting up tests has led me to put this repository together, with the following in mind:
- The repo can be used as-is with all main OpenFOAM forks
- Users only have to
- Write tests for their libraries; and of course ship them with custom
Makedirectories for complete compile-time freedom. - Provide their OpenFOAM test cases.
- Write tests for their libraries; and of course ship them with custom
- Tests should be fast. If you write small-enough tests, you should be able to get feedback on test fails without leaving your editor.
I'm assuming you're using this framework on a Linux machine, it can be a real one, a VM or a container, but there is no support for running this on Windows whatsoever.
To compile and run tests with this framework, you need:
- A sourced OpenFOAM installation.
- What's required to build Catch2 v3.x library
(mainly a recent
cmakewith common build essentials).
Note: HTML report generation via xsltproc is deprecated in v2.0.0. Use --report for JSON output instead.
- Tests are created and ran with Catch2 v3.x
- Catch2 docs and Phil's talk at CppCon 2018 are the best places to learn more
- No mocking library is shipped with the framework by default as I don't think mocking
is a good idea in general
- But you always can grab and use fakeIt for example.
- Each library you want to test has its own test driver
- Convention: The name of the test binary is always
testDriverand is compiled inside your tests directory for that library. - Each class's tests suite should be written in a separate
.Cfile
- Convention: The name of the test binary is always
- The same unit-test case can check for results both in serial and in parallel.
- In the presence of a mesh object, all tests that interact with it are "integration tests" at best.
- Tagging the test case is used to distinguish between serial/parallel tests, and to specify which OpenFOAM case to use to run the tests.
- Supported Catch2 reporters:
-
stdoutfor output at the console (Best for local and CI testing) -
compactfor status overview in a single line -
xmlandjunitfor Data Collectors
-
“This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks.”
This is foamUT Wiki, here is a link back to Home