jmockit / jmockit1

Advanced Java library for integration testing, mocking, faking, and code coverage
Other
461 stars 239 forks source link

Incorrect stacktrace for partially mocked class #677

Open msidnin opened 4 years ago

msidnin commented 4 years ago

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:

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:

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
        }