lightweight single header C++ library for embedding tests within your codebase - like documentation
DOCTEST_CONFIG_IMPLEMENT
is defined). There are 3 .dlls in total in the doctest example: 1 which has the test runner, 1 which just contains tests and 1 which is loaded at runtime by the program itself - also without a test runner.
DOCTEST_CONFIG_IMPLEMENT
is defined in a single place
DOCTEST_CONFIG_IMPLEMENT
and then include doctest.h you get the interface + the implementation
DOCTEST_CONFIG_IMPLEMENT
you pull the contents of that fictional .cpp along
The simple project have 2 dlls, dllA and dllB. I have a testrunner, which calls DOCTEST_CONFIG_IMPLEMENT
. I have a testexecutable which calls doctest:Contest()
. Each dlls calls DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
.
My question is, is this the best way to do it? Are there any other alternatives?
@syaifulnizamyahya This is the best way if you want to have a single test runner (a single place where DOCTEST_CONFIG_IMPLEMENT
is defined) - that way all the tests from all .dlls will be registered in a single place. This way you could choose which dlls to load from the executable and thus choose which tests to have registered. You could also use the command line filtering functionality to choose tests from specific .cpp files or based on a pattern or test suite - you could use test suites for the different dlls.
A potential alternative might be to have a test runner in each dll but then you would need to have DOCTEST_CONFIG_IMPLEMENT
in each dll and also create and use a doctest::Context
object in the dllMain
of each dll.
target_link_libraries(${LIBRARY_NAME}
doctest
)
#define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
#define DOCTEST_CONFIG_IMPLEMENT
#define DOCTEST_CONFIG_NO_SHORT_MACRO_NAMES
#include "doctest.h"
DOCTEST_TEST_CASE("testrunner") {
DOCTEST_INFO("From testrunner\n");
}
DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS
or DOCTEST_CONFIG_NO_EXCEPTIONS
or DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS
or DOCTEST_CONFIG_SUPER_FAST_ASSERTS
? What is the workflow that you guys use?
--no-breaks
from the command line options: https://github.com/onqtam/doctest/blob/master/doc/markdown/commandline.mdmain()
function with the ability to override it through the command line: https://github.com/onqtam/doctest/blob/master/doc/markdown/main.md (the option is used in the example as well - but as an override - move that above the call to applyCommandLine()
and it will be a default instead of an override)
#define INFO ...
which conflicts with the one from doctest? In that case you could use DOCTEST_CONFIG_NO_SHORT_MACRO_NAMES and perhaps a proxy header for including doctest like this: https://github.com/onqtam/doctest/blob/master/examples/all_features/doctest_proxy.h