tags:

views:

394

answers:

3
if(condition1)
 dosomething1();
if(condition2)
 dosomething2();
if(condition3)
 dosomething3();

Is it full branch testing if I have two test cases in this example

  1. condition1 = condition2 = condition3 = true;
  2. condition1 = condition2 = condition3 = false;

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.

+1  A: 

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.

Gavin Miller
Hmm this confuses me? I get your definition but if i remove the secound testcase doesnt this just end up being statement coverage?
bobjink
The second test case is redundant given the strict definition of branch testing... that is, the code before and after your if statements will get tested in case 1 and case 2. Therefore case 2 isn't doing anything new.
Gavin Miller
Thank you! This site uses two testcases: http://www.onjava.com/pub/a/onjava/2007/03/02/statement-branch-and-path-coverage-testing-in-java.html?page=1
bobjink
OK I dont get it. If I have done full statement coverage wouldnt I then also have full branch testing? How come branch testing is 'better'?
bobjink
@bobjink - Branch testing, is merely stopping ground on the road to Path testing.
Gavin Miller
Ye I think I get branch testing. All branches has to be executed. But doesnt all branches contain statements, therefor making it almost identical to statement coverage?
bobjink
yes - you're correct
Gavin Miller
A: 

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.

Greg Hewgill
Even so, 6? How did you get 8?
Stefan Mai
@Greg - That's path testing
Gavin Miller
@Stefan: 2^3 = 8, which is the number of combinations of three binary bits: 000, 001, 010, 011, 100, 101, 110, 111.
Greg Hewgill
@LFSR: Thanks, I wasn't able to find a definitive description of the difference by a quick google. One glossary I found defined them as exactly the same thing.
Greg Hewgill
I think thats the point of testing. Branch testing wont always tell you that your program is right. I think what you are thinking about is path testing.
bobjink
@Greg Wow. That's... thank you. One of the more glaring errors I've made this week.
Stefan Mai
A: 

Yes, you understand correctly. Branch testing is just "all branches are executed."

So I don't need the secound testcase?
bobjink