Getting java.lang.ExceptionInInitializerError when running Pit with Powermock

501 views
Skip to first unread message

grate Wite

unread,
May 12, 2017, 11:12:11 AM5/12/17
to PIT Users
Hi,

 I use PIT maven plugin 1.1.11, powermock 1.6.6, Junit 4.12. Below is the issue i am facing

    I wrote a test class to test my target class. My target class has a method which use a Singleton (enum) object to do some operation and get some value. Now, my singleton class has got some some attributes which are loaded through spring ( via applicationContext.getBean()) in constructor. This bean which i am loading via spring has got some dependencies which has got JNDI configuration to for data sources, jms connections etc etc. Now, to write Junit for my class, i need an instance of this Singleton class in my target class, but, due to the JNDI configurations in the spring dependencies i am trying to load, i am forced to mock the Singleton class using mockito.

Here is what i did

Created a base test class, and added below in static block
static{
      SimpleNamingContextBuilder builder = null;

        try {

            builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
            builder.bind("wm/myWm", new WorkManagerTaskExecutor());
            builder.bind("jms/ReqQueue", new MockDestination());
               .......
           builder.activate();

         } catch (NamingException e) {

            e.printStackTrace();

        }

 ApplicationContext context= new ClassPathXmlApplicationContext(new String[] {
                "application-context.xml", "mytest-beans.xml" });
}

}


Below is my test class

@RunWith(PowerMockRunner.class)
@PrepareForTest({MySingleton.class})
public class  MyTestClass extends BaseTestClass{

MySingletonClass mockSingleton=null;

TargetTestClass targetTestClass =null;

@Before
    public void setUp() {

        mockSingleton= PowerMockito.mock(MySingletonClass .class);
       
        Whitebox.setInternalState(MySingletonClass .class, "INSTANCE", mockSingleton);
      
        PowerMockito.when(mockSingleton,"getResult()",param,param,param,param).thenReturn(someObject);
}

   @Test
    public void testMethod_1(){

    targetTestClass= new TargetTestClass()
   
    Object result=  targetTestClass.testMethod(params...);

    Here goes assertions on result object.

 }
   

My Junit just runs fine, satisfies all conditions, no issues. But now, i want to try PIT, so added the plugin,  added target class and target tests (com.package.*) ,

run the command  mvn org.pitest:pitest-maven:mutationCoverage  and it fails.

Below is what i see in log as failure.


6:48:40 PM PIT >> INFO : MINION : 6:48:40 PM PIT >> WARNING : JUnit error for class class com.package.MyTestClass : com.package.MyTestClass

6:48:40 PM PIT >> INFO : MINION : 6:48:40 PM PIT >> WARNING : Not able to filter com.package.MyTestClass . Mutation may have prevented JUnit from constructing test

6:48:40 PM PIT >> FINE : MINION : FAIL Description [testClass=com.package.MyTestClass, name=testMethod_1(com.package.MyTestClass)] -> java.lang.ExceptionInInitializerError

I have another module for which PIT runs fine, so i dont have any doubts on configuration issues.

henry

unread,
May 12, 2017, 11:15:50 AM5/12/17
to PIT Users
What happens if you run with the latest version of pitest (1.2.0)?

grate Wite

unread,
May 12, 2017, 11:40:09 AM5/12/17
to PIT Users
Hi,

 Thank you for quickturn around.

 I just updated the version to 1.2.0. and run the test again, it didnt complete, got below error.

JVMDUMP039I Processing dump event "systhrow", detail "java/lang/OutOfMemoryError" at 2017/05/12 20:53:17 - please wait.

FYI, i have 44 classes in my package.

My system OS is windows 7 on 4GB RAM. Currently running soapui,command prompt, firefox, skype,  eclipse neon, Notepad++.

I tried updating the JVM argument as mentioned in the /quickstart/maven/ page

   <jvmArgs>
            <value>-Xmx1024m</value>
     </jvmArgs>

But still the same out of memmory.

Below info is what i see in logs during start

8:49:23 PM PIT >> INFO : Sending 44 test classes to minion
8:49:23 PM PIT >> INFO : Sent tests to minion
8:49:23 PM PIT >> INFO : MINION : 8:49:23 PM PIT >> INFO : Checking environment
8:49:23 PM PIT >> FINE : Expecting 44 tests classes from parent
8:49:23 PM PIT >> FINE : Tests classes received

8:49:37 PM PIT >> INFO : MINION : 8:49:37 PM PIT >> INFO : Found  469 tests

8:49:37 PM PIT >> INFO : MINION : 8:49:37 PM PIT >> INFO : Dependency analysis reduced number of potential tests by 0

8:49:37 PM PIT >> INFO : MINION : 8:49:37 PM PIT >> INFO : 469 tests received

8:49:37 PM PIT >> INFO : MINION : 8:49:37 PM PIT >> FINE : Running 469 units

Thanks

henry

unread,
May 12, 2017, 11:53:32 AM5/12/17
to PIT Users
Bit hard to say what's going on, except that something is broken.

If you can put together a minimal project that reproduces the issue I'll take a look.

Henry

grate Wite

unread,
May 12, 2017, 12:12:44 PM5/12/17
to PIT Users

 Let me try. The issue i was concerned about was the ExceptionInInitializerError .  

But, this OutOfMemoryError came when i used the version 1.2.0.

With 1.1.11, i was at least able to complete the run, but with  failure.

Thanks.
Reply all
Reply to author
Forward
0 new messages