EclEmma breaks mocking by JMockit (UnsupportedOperationException)

425 views
Skip to first unread message

martin....@gmail.com

unread,
Oct 7, 2015, 6:37:11 AM10/7/15
to JaCoCo and EclEmma Users
I use for my test cases the JMockit framework. If I mock an interface, test cases with such mocks doesn't run anymore with EclEmma (without they are working fine). I get an exception: java.lang.UnsupportedOperationException: class redefinition failed: attempted to change the schema (add/remove fields).

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.

rlies...@gmail.com

unread,
Oct 7, 2015, 10:58:41 AM10/7/15
to JaCoCo and EclEmma Users, martin....@gmail.com
For some context, what JMockit does in this example test is to generate an implementation class of name "$Impl_PreparedStatement". This is not a java.lang.reflect.Proxy subclass.

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.

Message has been deleted

martin....@gmail.com

unread,
Oct 7, 2015, 11:32:10 AM10/7/15
to JaCoCo and EclEmma Users, martin....@gmail.com, rlies...@gmail.com
Is fixed by pull https://github.com/jacoco/jacoco/pull/272, which is unfortunately not yet part of the current EclEmma version 2.3.2. Are there any plans for a new EclEmma release with the current JaCoCo version?

Marc R. Hoffmann

unread,
Oct 7, 2015, 11:34:32 AM10/7/15
to jac...@googlegroups.com
No plans, but you can install the EclEmma trunk build which is based on JaCoCo 0.7.5 release from this update site:

http://download.eclipselab.org/eclemma/trunk/update

Regards,
-marc


On 07.10.15 17:32, martin....@gmail.com wrote:

martin....@gmail.com

unread,
Oct 10, 2015, 4:30:50 PM10/10/15
to JaCoCo and EclEmma Users

Thanks! It's working :-)

Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages