Reputation: 3153
if(condition1)
dosomething1();
if(condition2)
dosomething2();
if(condition3)
dosomething3();
Is it full branch testing if I have two test cases in this example
Or have I misunderstood it? Trying to figure out the difference between branch and path testing. I get path testing so hope this is correct.
Upvotes: 1
Views: 7645
Reputation: 73
I disagree with the chosen answer that you can remove the second test line!
Wikipedia's definition of Branch testing states:
"Branch coverage – Has each branch (also called DD-path) of each control structure (such as in if and case statements) been executed? For example, given an if statement, have both the true and false branches been executed? Another way of saying this is, has every edge in the program been executed?"
Link here: https://en.wikipedia.org/wiki/Code_coverage
Also checkout this video lecture from Georgia Tech's Computer Science program on branch testing where this requirement is demonstrated in action.
Link here: https://www.youtube.com/watch?v=JkJFxPy08rk
Upvotes: 2
Reputation: 89
As per my understanding, Branch coverage is also known as Decision coverage and it covers both the true and false conditions
unlike the statement coverage. With an IF statement, the exit can either be TRUE or FALSE, depending on the value
of the logical condition that comes after IF.
Let us take one example to explain Branch coverage:
IF "A > B"
PRINT A is greater than B
ENDIF
So the Test Set for 100% branch coverage will be:
Test Case 1: A=5, B=2 which will return true.
Test Case 2: A=2, B=5 which will return false.
So in your case, both the test cases 1 and 2 are required for Branch coverage.
With only Test cases1, it will be statement coverage.
Upvotes: 2
Reputation: 11
To achieve 100% basis path coverage, you need to define your basis set. The cyclomatic complexity of this method is four (one plus the number of decisions), so you need to define four linearly independent paths. To do this, you pick an arbitrary first path as a baseline, and then flip decisions one at a time until you have your basis set.
Path 1: Any path will do for your baseline, so pick true for the decisions' outcomes (represented as TTT). This is the first path in your basis set.
Path 2: To find the next basis path, flip the first decision (only) in your baseline, giving you FTT for your desired decision outcomes.
Path 3: You flip the second decision in your baseline path, giving you TFT for your third basis path. In this case, the first baseline decision remains fixed with the true outcome.
Path 4 : Finally, you flip the third decision in your baseline path, giving you TTF for your fourth basis path. In this case, the first baseline decision remains fixed with the true outcome.
So, your four basis paths are TTT, FTT, TFT, and TTF. Now, make up your tests and see what happens.
Remember, the goal of basis path testing is to test all decision outcomes independently of one another
(Extract from http://www.codign.com/pathbranchcode.html)
Upvotes: 1
Reputation: 43875
Branch Testing:
Testing in which all branches in the program source code are tested at least once.
Yes; you are performing correct branch testing, since all your branches are hit. In fact you can remove your second test case, since case 1 executes all the branches.
Obviously branch testing is less encompassing than path testing, since it's likelyhood of hitting dependies is low and as such, ought not to be your only form of testing.
Upvotes: 3
Reputation:
Yes, you understand correctly. Branch testing is just "all branches are executed."
Upvotes: 0
Reputation: 994897
If I understand what you are asking, then you may need eight test cases to completely cover the alternatives in the given code. For example, what if dosomething2()
relies on some other state set up by dosomething1()
? Your test cases would not catch that requirement.
Upvotes: 0