My use case is for dotnet test, but I think this topic could apply to any collections of tests.
I’m writing a MSTest library that I register with ctest with a COMMAND dotnet test like so:
add_library(MyTestLibrary SHARED ...)
set_target_properties(MyTestLibrary PROPERTIES
VS_PACKAGE_REFERENCES "MSTest.TestAdapter_2.1.2;MSTest.TestFramework_2.1.2"
)
add_test(
NAME MyTestLibrary
COMMAND dotnet test $<TARGET_FILE:MyTestLibrary>
)
In terms of test execution, this works for me; I don’t need to filter individual tests within MyTestLibrary.
Now I want to add JUnit test results to the entire project. Since there are individual tests contained in MyTestLibrary, I plan to add a reference to JunitXml.TestLogger and then add to my command to expose them:
add_test(
NAME MyTestLibrary
COMMAND dotnet test $<TARGET_FILE:MyTestLibrary> --logger:junit
)
Now MyTestLibrary will generate its own JUnit, but this integrates poorly with ctest --output-junit because the ctest-generated JUnit will contain a block for MyTestLibrary when really I really want that to be covered by the one generated by the test itself.
My idea is to add a test label (e.g. set_tests_properties(MyTestLibrary PROPERTIES LABELS generates_junit)) and then run the tests separately so that the generated JUnits will be mutually exclusive.
ctest ... --output-junit <file> -LE generates_junit
ctest ... -L generates_junit
Is this a good idea? Any alternatives? Would it be a good feature request to add a new test properties (e.g. EXCLUDE_FROM_RESULTS) that would exclude my test from the ctest-generated JUnit so I could runs the tests together?
I recognize that Google Test handles this by discovering tests individually, but I thought that that approach would not work as well for managed tests (i.e. restarting dotnet test hundreds/thousands of times)