Skip to content
JUnit5 extensions to test Java System.x functions
Branch: develop
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

junit5-system-extensions (J5SE)

This project provides a set of JUnit 5 extension that allow testing behavior related to functions related to java.lang.System (e.g. asserting exit status codes).

Build Status Download


The extensions in this project were inspired by a set of JUnit4 rules called "System Rules" which were written by Stefan Brikner and licensed under the Common Public License 1.0 (CPL).

Runtime Dependencies

Dependency Purpose License
JUnit5 Unit test framework Eclipse Public License v2.0


Asserting System.exit(int) Calls

To trap and check calls to System.exit(int) follow these steps:

  1. Extend the test class with the class ExitGuard
  2. Use AssertExit.assertExit(Runnable) or AssertExit.assertExit(int, Runnable) to check for exit calls


import static org.itsallcode.junit.AssertExit.assertExit;

import org.itsallcode.junit.sysextensions.ExitGuard;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

class TestSystemExit
    void testSystemExit()
        assertExit(() -> System.exit(1));

Note that in order to be able to trap system exit, the ExitGuard temporarily replaces the existing security manager (if any).

Asserting Data Sent to System.out

To capture data sent to System.out, follow these steps:

  1. Extend the test class with SystemOutGuard
  2. Add a parameter of type Capturable to the test method (or the before-all-method)
  3. Activate capturing on the stream
  4. Run code under test
  5. Check captured data


import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

class TestSystemOut
    void testCapture(final Capturable stream)
        final String expected = "This text must be captured.";
        assertEquals(stream.getCapturedData(), expected);

Asserting Data Sent to System.err

Capturing data sent to System.err works in the exact same way as in the System.out case. The only difference is that you need to extend the test class with the SystemErrGuard.

Contributing, Feature Requests and Error Reporting

Please check our contribution guide to learn how you can help with the project, report errors or request features.


Build Time Dependencies

The list below show all build time dependencies in alphabetical order. Note that except the Maven build tool all required modules are downloaded automatically by Maven.

Dependency Purpose License
Apache Maven Build tool Apache License 2.0
License Maven Plugin Add licenses to source files automatically GNU Public License 3.0
Maven Compiler Plugin Maven provided and controlled Java compiler Apache License 2.0
Maven Source Plugin Create Source JAR packages Apache License 2.0
Maven JavaDoc Plugin Create JavaDoc JAR packages Apache License 2.0

Essential Build Steps

  • git clone
  • Run mvn test to run unit tests.
  • Run mvn package to create the JAR file.

Publishing to JCenter

  1. Add the following to your ~/.m2/settings.xml:

  2. Checkout the develop branch.

  3. Update version in pom.xml and, commit and push.

  4. Run command

    mvn deploy
  5. Merge to master branch

  6. Create a release of the master branch on GitHub.

  7. Sign in at

  8. Go to the Bintray project page

  9. Publish to Maven Central by clicking the "Sync" button at After some time the new version will appear at

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.