|
|
|
|
|
by dsp1234
3763 days ago
|
|
Imagine a function that is something like: function X(Y, Z){
if(Y){
foo();
}
if(Z){
bar();
}
}
If you have tests like: X(true, false);
X(false, true);
Then your code coverage from the "line" point of view is 100%. Those two tests execute every line of code. However, the two states: X(true, true);
X(false, false);
have not been tested, and if foo() and bar() both manipulate some global state, or otherwise have side effects, then the system could still break.This is an issue with many code coverage tools. The lines themselves have been executed, but not necessarily all program states. |
|
The advantage of unit testing modular code bases is that you don't have to test every program state, you just have to test every module state.
There is a huge difference in the feasibility of 100% code coverage if you need O(2^n) vs O(n) tests.
Even if your modules are highly coupled you should be able to mock away external dependencies and side-effects.