0

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.

3

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.

| improve this answer | |
  • So branch coverage means, that I cover all the possible scenarios? 8 in the first case? – plaidshirt Aug 31 '16 at 16:57
  • 1
    Branch aims to ensure that each one of the possible branch from each decision point is executed at least once and thereby ensuring that all reachable code is executed. So branch would the 3 tests because those three tests cover all the code statements. – Jon Raynor Aug 31 '16 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.