Search code examples
testingcode-coverage

In any program doesn't 100% statement coverage imply 100 % branch coverage?


While solving MCQs for a practice test I came across this statement - "In any program 100% statement coverage implies 100 % branch coverage" and it is termed as incorrect. I think its a correct statement because if we cover all the statements then it means we also cover all the paths and hence all the branches. Could someone please shed more light on this one?


Solution

  • Consider this code:

    ...
    if (SomeCondition) DoSomething();
    ...
    

    If SomeCondition is always true, you can have 100% statement coverage (SomeCondition and DoSomething() will be covered), but you never exercise the case when the condition is false, when you skip DoSomething().