Example:
public final class InterfaceMockTest {
@Test
public void test() throws SQLException {
MockUp<PreparedStatement> mock = new MockUp<PreparedStatement>() {
@Mock
public void setString(int parameterIndex, String x) {
System.out.println(x);
}
};
mock.getMockInstance().setString(1, "example");
}
}
I use EclEmma 2.3.2 as Eclipse plug-in. How can I make my tests with JMockit mocks running by EclEmma? Originally I have posted in the JMockit use group: https://groups.google.com/forum/#!topic/jmockit-users/Jzhxpt6MkMQ. There I have received the answer that JMockit doesn't add or remove any fields but JaCoCo does.
It has a protection domain with a code source but no location (mock.getMockInstance().getClass().getProtectionDomain().getCodeSource().getLocation() is null), which should allow the JaCoCo coverage transformer to detect it as a dynamically generated class with no source, and therefore ignore it. So, I am not seeing how the instrumentation gets to happen; or maybe it's not the generated class that's getting instrumented; would need to do some debugging.
Thanks! It's working :-)