Hello,
I have written Junit tests by mocking some methods using PowerMockito for testing Drools Rules.
The methods that I am mocking are static methods. I am first loading the Drools Rule Engine in
the setup method and then using
PowerMockito.mockStatic(StaticClass.class);
After that I am using the following line inside each test case to return different values depending on the
test case:
Mockito.when(StaticClass.StaticMethod(param)).thenReturn(value);
I have the following annotations set at the beginning of the test class:
@RunWith(PowerMockRunner.class)
@PowerMockIgnore({"javax.management.*", "javax.security.*" , "javax.crypto.*", "org.bouncycastle.*"})
@PrepareForTest({StaticClass.class})
I am using drools-6.3.0 and powermock-1.6.1 in my implementation.
The test cases executes properly in Eclipse, however when I try to build it using ant, it throws the following exception:
[junit] Exception in thread "main" java.lang.OutOfMemoryError: PermGen space
[junit] at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.createCDATASection(CoreDocumentImpl.java:585)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter.formatOutput(XMLJUnitResultFormatter.java:328)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter.setSystemOutput(XMLJUnitResultFormatter.java:122)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.sendOutAndErr(JUnitTestRunner.java:827)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:575)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1182)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:1033)
[junit] Exception in thread "Thread-0" java.lang.OutOfMemoryError: PermGen space
[junit] Exception in thread "Thread-2" java.lang.OutOfMemoryError: PermGen space
[junit] Exception in thread "Thread-4" java.lang.OutOfMemoryError: PermGen space
[junit] Exception in thread "Thread-3" java.lang.OutOfMemoryError: PermGen space
[junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 sec
BUILD FAILED
1) I tried increasing the PermGen space using
export ANT_OPTS="-Xmx2g -XX:MaxPermSize=512m" and
export JVM_ARGS="-Xmx1024m -XX:MaxPermSize=256m"
by varying the size. But the issue still exists.
2) I tried adding @PowerMockIgnore("org.drools.*") annotation but that did not help either.
3) This issue does not occur when using Mockito for non-static methods but as per my requirement,
all my methods have to be static only. Eg:
NonStaticClass obj = Mockito.mock(NonStaticClass.class);
Also this is my first time using PowerMockito with Drools, so is there something that I am missing?
Thanks,
Pavitra