1

I have a portion of code with three booleans, connected via "&&" like so:
bool1 && bool2 && bool3
During testing I debugged to this and found out that every boolean has a state of either true or false during all of the tests, so I would consider this sufficiently tested.
However, eclemma shows, that there is 1 of 6 branches, which is not covered.
As I found out by now, it is not possible to show which branch eclemma means (unfortunately), but I would additionally like to know, how eclemma reaches 6 branches?
From what I can see there are two possibilities:
1. use code optimization, so the evaluation of that expression is stopped after reaching the first "false", in this case, I would find 4 total states:
- false
- true - false
- true - true - false
- true - true - true
2. don't use code optimization, so in this case I would think that all 8 different states of the three booleans can be tested (2 * 2 * 2 = 8).

Can anyone help me out there, why eclemma is counting to 6 and what I can do to reach 100% test coverage?

ferrari2k
  • 461
  • 1
  • 5
  • 16
  • 3 booleans each can be in 2 state so 3 * 2 = 6. To reach 100% you need to pass each boolean as `false` and `true`. – Aleksandr M Jul 01 '15 at 09:28
  • Thanks for your comment although I am not so sure that is correct :) As I said, I have already ensured that each boolean is true and false during the tests. Additionally, there are indeed 8 states possible with 3 booleans, not just 6: true - true - true; true - true - false; true - false - true; true - false - false; And then with "false" at the beginning the remaining 4 states. – ferrari2k Jul 01 '15 at 09:40
  • I have to admit, the commentary formatting is a nightmare... sorry about that ;) – ferrari2k Jul 01 '15 at 09:43
  • Imagine that you have 3 `if`-s inside each other (first with `bool1`, second `bool2`...). First `if` can be `true` or `false`, second can be `true` or `false`... = 6. See http://www.istqb.guru/how-to-calculate-statement-branchdecision-and-path-coverage-for-istqb-exam-purpose/ and https://en.wikipedia.org/wiki/Code_coverage. – Aleksandr M Jul 01 '15 at 09:45
  • 1
    see http://stackoverflow.com/questions/10146032/missing-branches-when-using-asserttrue-instead-of-assertnull – soru Jul 01 '15 at 10:24

1 Answers1

0

If you'll write all 4 test cases as per your 1st possibility, it'll give you 100% coverage.