# JUnit Results for Collections of Tests

**URL:** https://discourse.cmake.org/t/junit-results-for-collections-of-tests/15845
**Category:** Usage
**Tags:** lang:csharp, tool:ctest
**Created:** [September 21, 2026, 3:53pm UTC](https://discourse.cmake.org/t/junit-results-for-collections-of-tests/15845 "2026-09-21T15:53:24Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![kevinyee](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/cdc98d/32.png) [@kevinyee](https://discourse.cmake.org/u/kevinyee)
#### Post date: [September 21, 2026, 3:53pm UTC](https://discourse.cmake.org/t/junit-results-for-collections-of-tests/15845/1 "2026-09-21T15:53:24Z")

</div>

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:

```auto
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:

```auto
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.

```auto
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)
