Conflict between Jacoco and Jmockit while running Unit Tests which uses Jmockit for Mocking.

2,248 views
Skip to first unread message

Praveen S P

unread,
Jun 13, 2017, 4:51:05 AM6/13/17
to JaCoCo and EclEmma Users
Hi Everyone ,

I m using Jacoco (Version : 0.7.9)  for Code Coverage and Jmockit (Version :1.28) for Mocking purpose while running my unit test cases. But is see a peculiar exception when execute my test cases with this combination of Jacoco and Jmockit.
 
Here is the Exception :
"java.lang.UnsupportedOperationException: class redefinition failed: attempted to change the schema (add/remove fields)".

I have used jmockit for mocking in my unti testcases. I see this exception in only those test cases where Jmockit mocking being used. Other Test cases which does not use any jmockit mocking are going fine.Hence this is a issue between jmockit and jacoco. I was trying to solve this issue for long time. I tried changing maven surefire plugin version, and  i saw that in this link "http://www.jacoco.org/jacoco/trunk/doc/changes.html" that this same issue has been solved in 0.7.3 .So i downgraded the version from 0.7.9 to 0.7.3 .But this also could not solve the issue . 

As per my understanding , there is a conflict when we use jacoco and jmockit simultaneously . So i want to know how to solve this issue and what is the solution for the conflict between jacoco and Jmockit.

can anyone help me on this ..Please..!! 


Thank You
-Praveen

Evgeny Mandrikov

unread,
Jun 13, 2017, 5:29:04 AM6/13/17
to JaCoCo and EclEmma Users
Hi,

To speedup understanding of your issue, please provide minimalistic example of project demonstrating this.

Regards,
Evgeny

Praveen S P

unread,
Jun 13, 2017, 7:32:33 AM6/13/17
to JaCoCo and EclEmma Users
Hi Evgeny,
Thanks for the quick reply

To explain further regarding the above issue , here is the small example.

These are two public java classes .

Class A:

public class A(){
      int a;
      public A(){}

      public int Method1(){
               a=10;
               return a;
         }
}

Class B:

public class B(){
       int b;
       private A object_of_a;

       public B(){}
       
       public int method2(){

                int c= object_of_a.Method1();
                b=b+c;
                return c;
       }
}


This is a Unit Test Class which is written for Class B. In this unit test case i m using Jmockit for mocking some of the methods.  

In the Below Test Case i m mocking the method Method1() of Class A using Jmockit and I use Jacoco agent to run the test case.

import org.testng.annotations.Test;
import org.junit.runner.RunWith;
import mockit.MockUp;
import mockit.Mock;

@Test
@RunWith(JMockit.class)
public class Test_B(){

       public Test_B(){}
       
       @BeforeClass
        public void setup() throws Exception {
        }

        @Test
         public void test_method2(){
                     
                     new MockUp(A){        < -- 10 ( Here i get Exception)
                          @Mock
                          public int Method1(){
                                   return 1290;
                           }   
                     };
                    
                    B b = new B();
                    int res = b.method2();
         }
}


Now , I execute my Test Case Test_B(). For this i use jacoco - maven -plugin 0.7.9 and Jmockit version 1.28.

When i execute the testcase with these two configuarations , My testcase is getting failed at Line 10 which is mentioned above with the exception  -- > "java.lang.UnsupportedOperationException: class redefinition failed: attempted to change the schema (add/remove fields)".

And,if i remove Jacoco plugin and just execute the test case as a normal test case without any jacoco agent in the command and using just jmockit version, It's works fine without any exception. So i m facing this issue when both jacoco and jmockit are used together.

I want to know how to solve this conflct or is this a bug in Jacoco version 0.7.9 which is not working fine with other plugins like Jmockit.

Thanks,
-Praveen

Evgeny Mandrikov

unread,
Jun 13, 2017, 10:35:04 AM6/13/17
to JaCoCo and EclEmma Users
Sorry, but what you provided is not even compilable ("public class A(){" - is not a valid class declaration) and contains strange mix of TestNG and JUnit annotations.
As a more reliable way of transfer please provide an archive that contains example that is complete (including pom.xml), compilable and runnable without exceptions without JaCoCo.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages