A JUnit5 Extension to help write tests that call System.exit()
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gradle/wrapper Update copyright Nov 11, 2018
src Adding JavaDoc Nov 11, 2018
.gitignore Initial commit Nov 11, 2018
LICENSE MIT License Nov 11, 2018
README.md Provide a handy-dandy README Nov 11, 2018
build.gradle Adding JavaDoc Nov 11, 2018
gradlew Initial commit Nov 11, 2018
gradlew.bat Initial commit Nov 11, 2018
settings.gradle Update copyright Nov 11, 2018

README.md

JUnit5 System.exit() Extension

This JUnit 5 Extension helps you write tests for code that calls System.exit(). Starting with JUnit 5, @Rules, @ClassRules, and Runners were replaced by the Extension concept.

Installing

Copy the following into your build.gradle or build.xml.

Gradle

testImplementation("com.ginsberg:junit5-system-exit:1.0.0")

Maven

<dependency>
    <groupId>com.ginsberg</groupId>
    <artifactId>junit5-system-exit</artifactId>
    <version>1.0.0</version>
    <scope>test</scope>
</dependency>

Use cases

A Test that expects System.out() to be called, with any status code:

public class MyTestCases { 
    
    @Test
    @ExpectSystemExit
    public void thatSystemExitIsCalled() {
        System.exit(1);
    }
}

A Test that expects System.out(1) to be called, with a specific status code:

public class MyTestCases {
    
    @Test
    @ExpectSystemExitWithStatus(1)
    public void thatSystemExitIsCalled() {
        System.exit(1);
    }
}

The @ExpectSystemExit and @ExpectSystemExitWithStatus annotations can be applied to methods, classs, or annotations (to act as meta-annotations).

Contributing and Issues

Please feel free to file issues for change requests or bugs. If you would like to contribute new functionality, please contact me first!

Copyright © 2018 by Todd Ginsberg