0

I try to run junit tests in parallel. But while my test has to finish they dont't. My jenkins running and seems like not gonna end.

The error is:
org.junit.contrib.java.lang.system.internal.CheckExitCalled: Tried to exit with status 0.
    at org.junit.contrib.java.lang.system.internal.NoExitSecurityManager.checkExit(NoExitSecurityManager.java:24)
    at java.lang.Runtime.exit(Runtime.java:107)
    at java.lang.System.exit(System.java:962)
    at org.apache.maven.surefire.booter.ForkedBooter.exit(ForkedBooter.java:144)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:127)
Exception in thread "main" org.junit.contrib.java.lang.system.internal.CheckExitCalled: Tried to exit with status 1.
    at org.junit.contrib.java.lang.system.internal.NoExitSecurityManager.checkExit(NoExitSecurityManager.java:24)
    at java.lang.Runtime.exit(Runtime.java:107)
    at java.lang.System.exit(System.java:962)
    at org.apache.maven.surefire.booter.ForkedBooter.exit(ForkedBooter.java:144)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:135)
Exception in thread "Thread-5" Exception in thread "Thread-6" org.junit.contrib.java.lang.system.internal.CheckExitCalled: Tried to exit with status 1.
    at org.junit.contrib.java.lang.system.internal.NoExitSecurityManager.checkExit(NoExitSecurityManager.java:24)
    at java.lang.Runtime.halt(Runtime.java:273)
    at org.apache.maven.surefire.booter.ForkedBooter$1.run(ForkedBooter.java:176)
    at java.lang.Thread.run(Thread.java:744)
org.junit.contrib.java.lang.system.internal.CheckExitCalled: Tried to exit with status 0.
    at org.junit.contrib.java.lang.system.internal.NoExitSecurityManager.checkExit(NoExitSecurityManager.java:24)
    at java.lang.Runtime.halt(Runtime.java:273)
    at org.apache.maven.surefire.booter.ForkedBooter$1.run(ForkedBooter.java:176)
    at java.lang.Thread.run(Thread.java:744)

In my class I have:

@Rule
public final ExpectedSystemExit expectedSystemExit = ExpectedSystemExit.none();

And

 if(carInsuranceSteps.isCheackReservationAddressNotFoundError()) {
            Thucydides.takeScreenshot();
            expectedSystemExit.expectSystemExitWithStatus(0);
            System.exit(0);
        }
java_user
  • 929
  • 4
  • 16
  • 39

1 Answers1

1

The exception is thrown by System Rules. It must replace the SecurityManager in order to test System.exit() and afterwards restores the original SecurityManager. This means that you cannot run multiple tests with System Rules in parallel in the same JVM.

Stefan Birkner
  • 24,059
  • 12
  • 57
  • 72
  • The problem is that you cannot run the tests in parallel because of the testing library that you're using (`ExpectedSystemExit` is part of System Rules.) – Stefan Birkner Mar 18 '16 at 07:47
  • Can you please suggest what can I do? – java_user Mar 18 '16 at 07:54
  • You could start each test in a separate JVM. See the ´forkCount´ option of Maven's Surefire plugin: https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html – Stefan Birkner Mar 18 '16 at 09:07
  • Thank you Sir I did and this work for me. Thank you for help one more time. – java_user Mar 18 '16 at 10:45
  • If I use ClassRule instead of Rule for ExpectedSystemExit I get the same exception. I suppose it shouldn't static as well – Sergii Getman Mar 21 '18 at 10:52
  • @SergiiGetman Why do you think that using a ClassRule instead of a Rule will help? – Stefan Birkner Mar 27 '18 at 12:07
  • 1
    @StefanBirkner I had the same exception as mentioned in question. I followed you explanation and realized that I used ClassRule. When I change it to Rule it works. So ClassRule -> Rule works to me – Sergii Getman Mar 27 '18 at 15:00