Show Menu

JUnit 5 Cheat Sheet by

JUnit 5 , for Fortgeschrittene Java Programmierung


Prepare Single
Clean Single
Prepare All
Cleanup All


assert­Tru­e(b­oolean b)
assert­Fal­se(­boolean b)
assert­Not­Nul­l(O­bject o)
assert­Nul­l(O­bject o)
assert­Not­Sam­e(O­bject unexpe­cted, actual)
assert­Equ­als­(ex­pected, actual)
assert­Not­Equals( unexpe­cted, actual)
assert­Arr­ayE­qua­ls(­Obj[] expected, actual)
assert­Ite­rab­leE­quals( expected, actual)
assert­Tim­eou­t(D­uration , Executable lambda)
assert­Thr­ows­(Class <T extends Throwa­ble> exClass, Executable lambda)
fail(S­tring message)


assume­Tru­e(b­oolean assumtion)
assume­Fal­se(­boolean assumtion, String msg)
* Failed assump­tions aborts test, not failure

* Assump­tions are typically used whenever it does not make sense to continue execution of a given test method


void exampleTest() {


        .assertNotSame(originalObject, otherObject);
    Assertions.assertEquals(4, 4);
    Assertions.assertNotEquals(3, 2);

            new int[]{1,2,3},
            new int[]{1,2,3},
            "Array Equal Test");

    Iterable<Integer> listOne = 
        new ArrayList<>(Arrays.asList(1,2,3,4));
    Iterable<Integer> listTwo =
        new ArrayList<>(Arrays.asList(1,2,3,4));
    Assertions.assertIterableEquals(listOne, listTwo);

    Assertions.assertTimeout(Duration.ofMillis(100), () -> {
        return "result";

    Throwable exception = Assertions
        () -> {
            new IllegalArgumentException(
              "error message");
        });"You shall not parse 🧙");


No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Eclipse Cheat Sheet
          OOv1 Cheat Sheet

          More Cheat Sheets by cs8898

          Java Annotation Cheat Sheet
          AspectJ Cheat Sheet