Boost Test + QuantLib
QuantLib has unit tests built in which are based on Boost Test.
How to build: $ cmake --build build --preset=MyPreset
$ cmake --build build/MyPreset --target ql-test-suite
How to run:$ ./build/MyPreset/test-suite/quantlib-test-suite
$ ./build/MyPreset/test-suite/quantlib-test-suite --list_content
$ ./build/MyPreset/test-suite/quantlib-test-suite --run_test="QuantLib test suite/Calendar tests/*"
How to add new tests:
- Option a: Append to already existing file
- Just add new static function in some test class
- E.g. in americanoption.hpp:AmericanOptionTest::newTest()
- Register in americanoption.cpp:AmericanOptionTest::suite()
- Creating a test function in anonymuous namespace in cpp and calling it in main test function is better for link time
- Just add new static function in some test class
- Option b: Create new Test file
- E.g. test-suite/newTests.{h,c}pp
- Implement test class (copy-paste from other files)
- Add files to
- test-suite/CMakeLists.txt: See QL_TEST_SOURCES, QL_TEST_HEADERS
- test-suite/testsuite.vcxproj{,.filters}
- test-suite/Makefile.am: See QL_TEST_SRCS, QL_TEST_HDRS
- Register test class in test-suite/quantlibtestsuite.cpp
For CMake preset see this post: CMake presets