Industry coverage
When writing test cases that should have 100% branch coverage, is it okay to have one of your cases that spans two branches and another case that only covers one.
note: we assume there are only three branches in the code.
edit: 3 branches means three main if statutes, all apart, inside the body of the code. eg.
input (x, y)
if (x<0)
something
if (x==y)
something
if (x > y)
something
output (x)
I have one test case that covers the first branch and one test case that covers the other two branches
The test is the question we have about the product. The idea of one test per (written) branch can be helpful or silly.
I have some questions about the example you are giving
input (x, y)
if (x <0)
something
if (x == y)
something
if (x> y)
something
output (x)
What happens if x is greater than zero? Should you fail? What should happen if x is less than y? Something? Nothing?
Here's the subject: code (and branch) (and condition) are good ideas. But what does it mean to "cover" a line or branch or condition? Should I make sure that the program can work, i.e. Execute a given line / branch / condition without crashing? Or do you need to make sure that this program will work?
--- Michael B.
a source to share
Personally, I focus on code behavior. Thus, there are three different possible ways of executing the code, as there should be three tests.
Think of it this way: if one of the two branches breaks, you might not know, because the test is still passing (since the other branch is still running), but the production code crashes. Not perfect.
Yes, it takes longer, but in some cases it's worth it ... 100% for everything? Maybe not to that level of extremes.
a source to share
100% branch coverage? Does the person asking about something like this have any experience in the real world? In my experience, for reasonably complex projects, getting 75-80% code coverage and 60-70% branch coverage is the best you can hope for. These numbers are usually raw, pre-analytical, numbers. They go up (~ 92-95% code and 80-85% branch) after inaccessible chunks such as Asserts, default switch cases, in-depth security codes, etc. are excluded. As for your question, the fewer test cases you have, the better. Keep in mind that tests take time not only to develop, but also to run and analyze failures. After waiting for your first time, you wait 4 days for the whole test suite to be completed, you will quickly learn how important it is to reduce the number of test cases to a minimum.which gives you confidence in coverage.
a source to share