Here is an example of an class with no behaviour at all. So the question is should I be doing unit test coverage for it, as I see it as unnecessary for it does have any behaviour in it.
public class Employee
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public Address Address { get; set; }
}
My code coverage result complains that I have not done any coverage for the class
Aim for 95% or higher coverage with unit tests for new application code. When developers unit test as they program, they improve the longevity and quality of the codebase. The time a development team invests in unit tests pays off with less time spent troubleshooting defects and analyzing problems later.
The purpose of a unit test in software engineering is to verify the behavior of a relatively small piece of software, independently from other parts. Unit tests are narrow in scope, and allow us to cover all cases, ensuring that every single part works correctly.
While project wide goals above 90% are most likely not worth it, per-commit coverage goals of 99% are reasonable, and 90% is a good lower threshold. We need to ensure that our tests are not getting worse over time. Unit test code coverage is only a piece of the puzzle.
Criticism Of Code CoverageMany software testing experts argue that code coverage is not a good metric for software testing teams, even though it is often used to measure team performance. That's not to say coverage doesn't have its uses—as Martin Fowler points out, it is a good way to identify untested code.
I never write tests for these. There's no behavior to test.
If there were any non-trivial behavioral code whatsoever (validation code, perhaps), then I would write a test for it.
I found this interesting article from Martin Fowler:
Test coverage is a useful tool for finding untested parts of a codebase. Test coverage is of little use as a numeric statement of how good your tests are.
===
Also this interesting quote from Object mentor:
It’s probably not mandatory and if your goal is 100% coverage, you’ll focus on that goal and not focus on writing the best tests for the behavior of your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With