Sam Shiles
Sam Shiles

Reputation: 11259

Code Coverage Tools and TDD

I've recently been evaluating DotCover by JetBrains and it's led me to a interesting question.

When following TDD:

If during the process of the refactoring I move some functionality into its own class (say for the sake of adhering to DRY or SRP), and then rerun DotCover, the coverage % will then drop as I'm no longer directly testing the new class.

This seems a bit strange to me as I'm following the tenets of TDD to the absolute letter. If I modify or comment out any line in the code, a test WILL break, yet it is reported as uncovered.

Am I missing something?

Upvotes: 1

Views: 353

Answers (2)

Karl Gjertsen
Karl Gjertsen

Reputation: 4928

I suppose this opens the argument of the definition of Unit Test vs Integration Tests.

You can use filters to exclude areas from the code coverage: http://blogs.jetbrains.com/dotnet/2010/07/filtering-with-dotcover/

Hope this helps.

Upvotes: 0

Carl Manaster
Carl Manaster

Reputation: 40356

DotCover may want your units to be tested as units, thus the penalty for indirect testing. And there's some merit to the argument that only the system under test should be considered in testing; when you extract a class but test it through the caller, you're really testing the caller and should (arguably) mock the new class - and have true unit tests for the new class, which test it as an independent unit.

Upvotes: 2

Related Questions