Take for example the following ficticious example:
public class Calculator {
BigDecimal currentValue = new BigDecimal(0);
Stack history = new Stack();
public void add(BigDecimal augend) {
currentValue = currentValue.add(augend);
commandPerformed(Type.ADD,augend);
}
private void commandPerformed(Type type, BigDecimal augend) {
// TODO Auto-generated method stub
System.out.println(type+": "+augend);
}
public void undo() {
// TODO
}
public void redo() {
// TODO
}
}
Initially the coverage report will show that all of this class is not covered.
Create a test for the add() function, and the code coverage reports will show that the commandPerformed() has been covered -- even though it is clearly not doing what it is suppoed to.
Be careful when reading code coverage reports -- don't assume that code that is covered is tested. The most a coverage report can tell you is if code is not covered at all by your tests.

5 comments:
Code Converage + JUnit Tests + JMock should be less misleading ;)
How does adding JMock into the mix help?
Using JMock to keep track of which all methods have been invoked on your test object and failing if there have not been invocations on all public methods of your test object.
sounds like that could be helpful. Does JMock differentiate between method calls made by arbitrary code and method calls made by your JUnit tests?
typically you use jmock only inside your test cases :). jmock will keep track of the mock object only and provide info on calls on that mock object
Post a Comment