If tested class is partially mocked - it's impossible to see the exception source from a stacktrace. Such a stacktrace confuses a developer.
Test class:
import mockit.Expectations;
import mockit.Tested;
import org.junit.Test;
public class StackTraceIssueTest {
private @Tested StackTraceIssue issue;
@Test
public void okStackTrace() {
issue.someMethod();
}
@Test
public void wrongStackTrace() {
new Expectations( issue ) {
{
}
};
issue.someMethod();
}
}
Target class:
public class StackTraceIssue {
public void someMethod() {
throw new UnsupportedOperationException();
}
}
Results:
okStackTrace:
java.lang.UnsupportedOperationException
at StackTraceIssue.someMethod(StackTraceIssue.java:4)
at StackTraceIssueTest.okStackTrace(StackTraceIssueTest.java:11)
wrongStackTrace:
java.lang.UnsupportedOperationException
at StackTraceIssueTest.wrongStackTrace(StackTraceIssueTest.java:20)
If exception is caught and printed - than test also shows it correctly:
try {
issue.someMethod();
} catch ( Exception e ) {
e.printStackTrace();
throw e; // will be printed correctly
}
JMockit version: 1.49 (and 1.34)
If tested class is partially mocked - it's impossible to see the exception source from a stacktrace. Such a stacktrace confuses a developer.
Test class:
Target class:
Results:
If exception is caught and printed - than test also shows it correctly: