Annotations
|
|
Prepare Single |
|
Clean Single |
|
Prepare All |
|
Cleanup All |
Assertions
|
assertFalse(boolean b)
|
assertNotNull(Object o)
|
|
assertNotSame(Object unexpected, actual)
|
assertEquals(expected, actual)
|
assertNotEquals( unexpected, actual)
|
assertArrayEquals(Obj[] expected, actual)
|
assertIterableEquals( expected, actual)
|
assertTimeout(Duration , Executable lambda)
|
assertThrows(Class <T extends Throwable> exClass, Executable lambda)
|
|
Assumptions
assumeTrue(boolean assumtion)
|
assumeFalse(boolean assumtion, String msg)
|
* Failed assumptions aborts test, not failure
* Assumptions are typically used whenever it does not make sense to continue execution of a given test method
|
|
Sample
@org.junit.jupiter.api.Test
void exampleTest() {
Assertions.assertTrue(trueBool);
Assertions.assertFalse(falseBool);
Assertions.assertNotNull(notNullString);
Assertions.assertNull(notNullString);
Assertions
.assertNotSame(originalObject, otherObject);
Assertions.assertEquals(4, 4);
Assertions.assertNotEquals(3, 2);
Assertions
.assertArrayEquals(
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), () -> {
Thread.sleep(50);
return "result";
});
Throwable exception = Assertions
.assertThrows(IllegalArgumentException.class,
() -> {
throw
new IllegalArgumentException(
"error message");
});
Assertions.fail("You shall not parse 🧙");
}
|
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by cs8898