Code Snippet

Just another Code Snippet site

[JUnit] Test System.exit value

public class TestClass {

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

    @Test
    public void test1()  {
        exit.expectSystemExitWithStatus(1);

        // Call method with exit status
        ClassWithExitReturn.execute();
    }
}

Maven dependency :

<dependency>
  <groupId>com.github.stefanbirkner</groupId>
  <artifactId>system-rules</artifactId>
  <version>1.5.0</version>
</dependency>


Comments are currently closed.