1

I have a project A for which I wrote unit tests in test project UnitTests. I use MSTest.

I wrote some testing utils in the file UnitTestUtils.cs which simplify testing project A. I also covered these utils with unit tests.

The file structure now is

  • A
    • Program.cs
  • UnitTests
    • Utils
      • UnitTestUtils.cs
    • Tests.cs <- (A_SomeTest1, A_SomeTest2, ...)
    • UtilsTests.cs <- (Utils_SomeTest1, ...)

All tests for A are prefixed by A_ and all tests for utils are prefixed by Utils_.

I want to run code coverage for test utils using coverlet.collector like in this instruction. I can specify a prefix for tests which I want to run by using dotnet test --filter Utils, but code coverage gives me not coverage of my testing utils, but for the project A.

How can I run code coverage for my testing utils?

Liam
  • 27,717
  • 28
  • 128
  • 190
elo
  • 489
  • 3
  • 13
  • Code coverage isn't calculates on the tests. It's calculated on the code. So is there anyway to tell which code in `A` is covered by `Utils`? – Liam Nov 25 '21 at 08:49
  • Actually, I don't want to check code coverage for ```A``` inside ```Utils```. All I want is to check coverage of ```UnitTestUtils.cs``` by ```UtilsTests.cs``` – elo Nov 25 '21 at 08:52
  • Your unit testing your unit tests? – Liam Nov 25 '21 at 08:54
  • I wrote helper classes for unit testing, and they are obviously must be tested too – elo Nov 25 '21 at 09:18
  • why obviously? That seems like a strange pattern. I'd suggest you abstract these out into their own assembly and then unit test that if you want code coverage. But calculating code coverage on unit tests seems like an odd thing to do... – Liam Nov 25 '21 at 09:22
  • Well, I found out a few bugs while was writing unit tests for them. Ok, thanks for helping – elo Nov 25 '21 at 09:25

0 Answers0