Question

I have found several documents about statement and decision/branch coverage in testing, but these terms aren't clear for me. There are two types of this problems, that you can see below.

Code:

    if(a || b)) {
    test1 = true;
    }
    else {
        if(c) {
        test2 = true
        }
    }
}

Text:

Consider the following: Pick up and read the newspaper Look at what is on television If there is a program that you are interested in watching then switch the television on and watch the program Otherwise Continue reading the newspaper If there is a crossword in the newspaper then try and complete the crossword

Could you please best practices, how to found out sc and dc values in an easy way? I can't some exact methodology behind these values.

Was it helpful?

Solution

Test coverage indicates if all code paths are being covered.

So, in your example above you have 3 paths or outcomes:

  • test1 is set to true
  • test2 is set to true
  • Neither test1 and test2 are set to true

So, you only need 3 tests to cover the code paths/outcomes.

But we have 3 data points, a,b,c. Let's say these are Boolean values so we would need 2 to the 3rd power or 8 tests to test all possible scenarios.

So, if you wrote 1 test you would cover 33% of the code and 12.5% percent of all possibilities.

For complex programs covering all possibilities is not very feasible from a time and effort standpoint so there are tools to measure code coverage (how much code are your tests are covering). But one should strive for good code coverage so that all system behavior is tested. Covering all possibilities is usually not feasible because of combinational explosion.

Licensed under: CC-BY-SA with attribution
scroll top