---
title: "Test Coverage and testing angles"
url: "https://osherove.com/blog/2005/4/3/test-coverage-and-testing-angles.md"
canonical: "https://osherove.com/blog/2005/4/3/test-coverage-and-testing-angles.html"
published: "2005-04-03T09:54:00"
updated: "2005-04-03T09:54:00"
tags: ["Agile Related", "Testing Guidelines"]
author: "Roy Osherove"
description: "How do you know if you have good coverage on your new code? Try and remove a line or a constraint check . If all tests still pass – you don't have enough code coverage and you probably need to add another unit test. The…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Test Coverage and testing angles

By Roy Osherove April 3, 2005 In [Agile Related](https://osherove.com/blog/category/agile-related), [Testing Guidelines](https://osherove.com/blog/category/testing-guidelines)

**Historical article** · Originally published April 3, 2005; technical details may be outdated.

How do you know if you have good coverage on your new code?

**Try and remove a line or a constraint check**. If all tests still pass – you don't have enough code coverage and you probably need to add another unit test.

The best way to make sure you are adding the correct test is to not let yourself uncomment that line or check until you can produce a test that will fail until you uncomment it. It may be hard but if you can’t think of a way this would fail, you probably don’t have a good excuse for writing that line of code, do you?

Why is this a problem? Because you never know when the next developer will show up and try to play with your code, maybe try to optimize it, or wrongly delete some precious line of your code.  If you don’t have a test that will fail, they will never know they made a mistake.

You might also want to try and replace various usage of parameters that are passed in to your method with consts. For example given this method,

```
Public int Sum(int x, int y, bool allowNegatives)
{
   If(!allowNegatives)
{
        If(x<0||y<0)
        Throw new Exception();
}
   Return x+y;
}
```

here are some variations of testing for test coverage:

```
If(!true)
{
        If(x<0||y<0)
        Throw new Exception();
}
 
Or
 
   If(!allowNegatives)
{
        If(false||y<0)
        Throw new Exception();
}
 
Or
 
If(!allowNegatives)
{
        If(x<0||false)
        Throw new Exception();
}
```

If all the tests still pass, you’re missing a test.

Another red flag: If you have only one test that checks for various equality to values.

Seeing this:

```
Assert.AreEqual(3,retval);
```

Happen only once in relation to some method usually means you can safely return 3 as a value and all the tests for this method will still pass.

## Lessons on this topic

- [Debugging Excursions](https://courses.osherove.com/courses/tdd-pairing-sessions-building-a-go-game/debugging-excursions/) · TDD Pairing Sessions - Building a Go Game
- [Test Driving a String Calculator](https://courses.osherove.com/courses/the-art-of-unit-testing-and-tdd-master-class-in-net/test-driving-a-string-calculator/) · The Art of Unit Testing & TDD Master Class in .NET
- [Test Review Practices](https://courses.osherove.com/courses/the-art-of-unit-testing-and-tdd-master-class-in-net/test-review-practices/) · The Art of Unit Testing & TDD Master Class in .NET
- [Unit Testing And TDD 101](https://courses.osherove.com/courses/the-art-of-unit-testing-and-tdd-master-class-in-net/unit-testing-and-tdd-101/) · The Art of Unit Testing & TDD Master Class in .NET
- [Common Questions and Answers about Test Driven Development](https://courses.osherove.com/courses/tdd-and-bdd-in-ruby/common-questions-and-answers-about-test-driven-development/) · TDD and BDD in Ruby

## More in Agile Related

[All posts in Agile Related](https://osherove.com/blog/category/agile-related)

- Apr 3, 2005

    ### [Migrating Nunit 1.0 to 2.2.2 - step by step walkthrough](https://osherove.com/blog/2005/4/3/migrating-nunit-10-to-222-step-by-step-walkthrough.html)

- Apr 3, 2005

    ### [When should you remove or change a unit test?](https://osherove.com/blog/2005/4/3/when-should-you-remove-or-change-a-unit-test.html)

- Apr 3, 2005

    ### [A Unit test should test only one thing](https://osherove.com/blog/2005/4/3/a-unit-test-should-test-only-one-thing.html)

- Apr 3, 2005

    ### [Naming standards for unit tests](https://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
