Assertions is a collection of utility methods that support asserting
conditions in tests.
Unless otherwise noted, a failed assertion will throw an
org. or a subclass thereof.
Assertion methods comparing two objects for equality, such as the
assertEquals(expected, actual) and assertNotEquals(unexpected, actual)
variants, are only intended to test equality for an (un-)expected value
and an actual value. They are not designed for testing whether a class correctly
implements Object#equals(Object). For example, assertEquals()
might immediately return true when provided the same object for the
expected and actual values, without calling equals(Object) at all.
Tests that aim to verify the equals(Object) implementation should instead
be written to explicitly verify the Object#equals(Object) contract by
using assertTrue() or assertFalse() — for example, assertTrue(expected.equals(actual)),
assertTrue(actual.equals(expected)), assertFalse(expected.equals(null)),
etc.
Additional Kotlin assertions can be
found as top-level functions in the org.
package.
The various assertTimeoutPreemptively() methods in this class
execute the provided callback (executable or supplier) in a
different thread than that of the calling code. If the timeout is exceeded,
an attempt will be made to preemptively abort execution of the callback by
interrupting the callback's thread. If the
callback's thread does not return when interrupted, the thread will continue
to run in the background after the assertTimeoutPreemptively() method
has returned.
Furthermore, the behavior of assertTimeoutPreemptively() methods
can lead to undesirable side effects if the code that is executed within the
callback relies on ThreadLocal storage. One common example of this is
the transactional testing support in the Spring Framework. Specifically, Spring's
testing support binds transaction state to the current thread (via a
ThreadLocal) before a test method is invoked. Consequently, if a
callback provided to assertTimeoutPreemptively() invokes Spring-managed
components that participate in transactions, any actions taken by those
components will not be rolled back with the test-managed transaction. On the
contrary, such actions will be committed to the persistent store (e.g.,
relational database) even though the test-managed transaction is rolled back.
Similar side effects may be encountered with other frameworks that rely on
ThreadLocal storage.
Although it is technically possible to extend this class, extension is strongly discouraged. The JUnit Team highly recommends that the methods defined in this class be used via static imports.
org.opentest4j.AssertionFailedError , Assumptions
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public static void | |
| public static void | assertAll(@Nullable String heading, Executable... executables)
Assert that all supplied |
| public static void | assertAll(Collection<Executable> executables)
Assert that all supplied |
| public static void | assertAll(@Nullable String heading, Collection<Executable> executables)
Assert that all supplied |
| public static void | assertAll(Stream<Executable> executables)
Assert that all supplied |
| public static void | assertAll(@Nullable String heading, Stream<Executable> executables)
Assert that all supplied |
| public static void | assertArrayEquals(@Nullable boolean[] expected, @Nullable boolean[] actual)
Assert that |
| public static void | assertArrayEquals(@Nullable boolean[] expected, @Nullable boolean[] actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertArrayEquals(@Nullable char[] expected, @Nullable char[] actual)
Assert that |
| public static void | assertArrayEquals(@Nullable char[] expected, @Nullable char[] actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertArrayEquals(@Nullable byte[] expected, @Nullable byte[] actual)
Assert that |
| public static void | assertArrayEquals(@Nullable byte[] expected, @Nullable byte[] actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertArrayEquals(@Nullable short[] expected, @Nullable short[] actual)
Assert that |
| public static void | assertArrayEquals(@Nullable short[] expected, @Nullable short[] actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertArrayEquals(@Nullable int[] expected, @Nullable int[] actual)
Assert that |
| public static void | assertArrayEquals(@Nullable int[] expected, @Nullable int[] actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertArrayEquals(@Nullable long[] expected, @Nullable long[] actual)
Assert that |
| public static void | assertArrayEquals(@Nullable long[] expected, @Nullable long[] actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertArrayEquals(@Nullable float[] expected, @Nullable float[] actual)
Assert that |
| public static void | assertArrayEquals(@Nullable float[] expected, @Nullable float[] actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertArrayEquals(@Nullable float[] expected, @Nullable float[] actual, float delta)
Assert that |
| public static void | assertArrayEquals(@Nullable float[] expected, @Nullable float[] actual, float delta, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertArrayEquals(@Nullable double[] expected, @Nullable double[] actual)
Assert that |
| public static void | assertArrayEquals(@Nullable double[] expected, @Nullable double[] actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertArrayEquals(@Nullable double[] expected, @Nullable double[] actual, double delta)
Assert that |
| public static void | assertArrayEquals(@Nullable double[] expected, @Nullable double[] actual, double delta, @Nullable String message)
Assert that |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertDoesNotThrow(Executable executable)
Assert that execution of the supplied |
| public static void | assertDoesNotThrow(Executable executable, @Nullable String message)
Assert that execution of the supplied |
| public static void | assertDoesNotThrow(Executable executable, Supplier<@Nullable String> messageSupplier)
Assert that execution of the supplied |
| public static <T extends @Nullable Object> T | assertDoesNotThrow(ThrowingSupplier<T> supplier)
Assert that execution of the supplied |
| public static <T extends @Nullable Object> T | assertDoesNotThrow(ThrowingSupplier<T> supplier, @Nullable String message)
Assert that execution of the supplied |
| public static <T extends @Nullable Object> T | assertDoesNotThrow(ThrowingSupplier<T> supplier, Supplier<@Nullable String> messageSupplier)
Assert that execution of the supplied |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertEquals(@Nullable Short expected, @Nullable Short actual)
Assert that |
| public static void | assertEquals(short expected, short actual, @Nullable String message)
Assert that |
| public static void | assertEquals(short expected, @Nullable Short actual, @Nullable String message)
Assert that |
| public static void | assertEquals(@Nullable Short expected, short actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertEquals(short expected, short actual, Supplier<@Nullable String> messageSupplier)
Assert that |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertEquals(@Nullable Byte expected, @Nullable Byte actual)
Assert that |
| public static void | assertEquals(byte expected, byte actual, @Nullable String message)
Assert that |
| public static void | assertEquals(byte expected, @Nullable Byte actual, @Nullable String message)
Assert that |
| public static void | assertEquals(@Nullable Byte expected, byte actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertEquals(byte expected, byte actual, Supplier<@Nullable String> messageSupplier)
Assert that |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertEquals(@Nullable Integer expected, @Nullable Integer actual)
Assert that |
| public static void | assertEquals(int expected, int actual, @Nullable String message)
Assert that |
| public static void | assertEquals(int expected, @Nullable Integer actual, @Nullable String message)
Assert that |
| public static void | assertEquals(@Nullable Integer expected, int actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertEquals(int expected, int actual, Supplier<@Nullable String> messageSupplier)
Assert that |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertEquals(@Nullable Long expected, @Nullable Long actual)
Assert that |
| public static void | assertEquals(long expected, long actual, @Nullable String message)
Assert that |
| public static void | assertEquals(long expected, @Nullable Long actual, @Nullable String message)
Assert that |
| public static void | assertEquals(@Nullable Long expected, long actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertEquals(long expected, long actual, Supplier<@Nullable String> messageSupplier)
Assert that |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertEquals(@Nullable Float expected, @Nullable Float actual)
Assert that |
| public static void | assertEquals(float expected, float actual, @Nullable String message)
Assert that |
| public static void | assertEquals(float expected, @Nullable Float actual, @Nullable String message)
Assert that |
| public static void | assertEquals(@Nullable Float expected, float actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertEquals(float expected, float actual, Supplier<@Nullable String> messageSupplier)
Assert that |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertEquals(float expected, float actual, float delta)
Assert that |
| public static void | assertEquals(float expected, float actual, float delta, @Nullable String message)
Assert that |
| public static void | assertEquals(float expected, float actual, float delta, Supplier<@Nullable String> messageSupplier)
Assert that |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertEquals(@Nullable Double expected, @Nullable Double actual)
Assert that |
| public static void | assertEquals(double expected, double actual, @Nullable String message)
Assert that |
| public static void | assertEquals(double expected, @Nullable Double actual, @Nullable String message)
Assert that |
| public static void | assertEquals(@Nullable Double expected, double actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertEquals(double expected, double actual, Supplier<@Nullable String> messageSupplier)
Assert that |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertEquals(double expected, double actual, double delta)
Assert that |
| public static void | assertEquals(double expected, double actual, double delta, @Nullable String message)
Assert that |
| public static void | assertEquals(double expected, double actual, double delta, Supplier<@Nullable String> messageSupplier)
Assert that |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertEquals(@Nullable Character expected, @Nullable Character actual)
Assert that |
| public static void | assertEquals(char expected, char actual, @Nullable String message)
Assert that |
| public static void | assertEquals(char expected, @Nullable Character actual, @Nullable String message)
Assert that |
| public static void | assertEquals(@Nullable Character expected, char actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertEquals(char expected, char actual, Supplier<@Nullable String> messageSupplier)
Assert that |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertEquals(@Nullable Object expected, @Nullable Object actual)
Assert that |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertFalse(boolean condition, @Nullable String message)
Assert that the supplied |
| public static void | assertFalse(boolean condition, Supplier<@Nullable String> messageSupplier)
Assert that the supplied |
| public static void | assertFalse(BooleanSupplier booleanSupplier)
Assert that the boolean condition supplied by |
| public static void | assertFalse(BooleanSupplier booleanSupplier, @Nullable String message)
Assert that the boolean condition supplied by |
| public static void | assertFalse(BooleanSupplier booleanSupplier, Supplier<@Nullable String> messageSupplier)
Assert that the boolean condition supplied by |
| public static <T> T | assertInstanceOf(Class<T> expectedType, @Nullable Object actualValue)
Assert that the supplied |
| public static <T> T | |
| public static <T> T | |
| public static void | assertIterableEquals(@Nullable Iterable<?> expected, @Nullable Iterable<?> actual)
Assert that |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertNotEquals(byte unexpected, @Nullable Byte actual)
Assert that |
| public static void | assertNotEquals(@Nullable Byte unexpected, byte actual)
Assert that |
| public static void | assertNotEquals(@Nullable Byte unexpected, @Nullable Byte actual)
Assert that |
| public static void | assertNotEquals(byte unexpected, byte actual, @Nullable String message)
Assert that |
| public static void | assertNotEquals(byte unexpected, @Nullable Byte actual, @Nullable String message)
Assert that |
| public static void | assertNotEquals(@Nullable Byte unexpected, byte actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertNotEquals(byte unexpected, byte actual, Supplier<@Nullable String> messageSupplier)
Assert that |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertNotEquals(short unexpected, @Nullable Short actual)
Assert that |
| public static void | assertNotEquals(@Nullable Short unexpected, short actual)
Assert that |
| public static void | assertNotEquals(@Nullable Short unexpected, @Nullable Short actual)
Assert that |
| public static void | assertNotEquals(short unexpected, short actual, @Nullable String message)
Assert that |
| public static void | assertNotEquals(short unexpected, @Nullable Short actual, @Nullable String message)
Assert that |
| public static void | assertNotEquals(@Nullable Short unexpected, short actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertNotEquals(short unexpected, short actual, Supplier<@Nullable String> messageSupplier)
Assert that |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertNotEquals(int unexpected, @Nullable Integer actual)
Assert that |
| public static void | assertNotEquals(@Nullable Integer unexpected, int actual)
Assert that |
| public static void | assertNotEquals(@Nullable Integer unexpected, @Nullable Integer actual)
Assert that |
| public static void | assertNotEquals(int unexpected, int actual, @Nullable String message)
Assert that |
| public static void | assertNotEquals(int unexpected, @Nullable Integer actual, @Nullable String message)
Assert that |
| public static void | assertNotEquals(@Nullable Integer unexpected, int actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertNotEquals(int unexpected, int actual, Supplier<@Nullable String> messageSupplier)
Assert that |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertNotEquals(long unexpected, @Nullable Long actual)
Assert that |
| public static void | assertNotEquals(@Nullable Long unexpected, long actual)
Assert that |
| public static void | assertNotEquals(@Nullable Long unexpected, @Nullable Long actual)
Assert that |
| public static void | assertNotEquals(long unexpected, long actual, @Nullable String message)
Assert that |
| public static void | assertNotEquals(long unexpected, @Nullable Long actual, @Nullable String message)
Assert that |
| public static void | assertNotEquals(@Nullable Long unexpected, long actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertNotEquals(long unexpected, long actual, Supplier<@Nullable String> messageSupplier)
Assert that |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertNotEquals(float unexpected, @Nullable Float actual)
Assert that |
| public static void | assertNotEquals(@Nullable Float unexpected, float actual)
Assert that |
| public static void | assertNotEquals(@Nullable Float unexpected, @Nullable Float actual)
Assert that |
| public static void | assertNotEquals(float unexpected, float actual, @Nullable String message)
Assert that |
| public static void | assertNotEquals(float unexpected, @Nullable Float actual, @Nullable String message)
Assert that |
| public static void | assertNotEquals(@Nullable Float unexpected, float actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertNotEquals(float unexpected, float actual, Supplier<@Nullable String> messageSupplier)
Assert that |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertNotEquals(float unexpected, float actual, float delta)
Assert that |
| public static void | assertNotEquals(float unexpected, float actual, float delta, @Nullable String message)
Assert that |
| public static void | assertNotEquals(float unexpected, float actual, float delta, Supplier<@Nullable String> messageSupplier)
Assert that |
| public static void | |
| public static void | assertNotEquals(double unexpected, @Nullable Double actual)
Assert that |
| public static void | assertNotEquals(@Nullable Double unexpected, double actual)
Assert that |
| public static void | assertNotEquals(@Nullable Double unexpected, @Nullable Double actual)
Assert that |
| public static void | assertNotEquals(double unexpected, double actual, @Nullable String message)
Assert that |
| public static void | assertNotEquals(double unexpected, @Nullable Double actual, @Nullable String message)
Assert that |
| public static void | assertNotEquals(@Nullable Double unexpected, double actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertNotEquals(double unexpected, double actual, Supplier<@Nullable String> messageSupplier)
Assert that |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertNotEquals(double unexpected, double actual, double delta)
Assert that |
| public static void | assertNotEquals(double unexpected, double actual, double delta, @Nullable String message)
Assert that |
| public static void | assertNotEquals(double unexpected, double actual, double delta, Supplier<@Nullable String> messageSupplier)
Assert that |
| public static void | |
| public static void | assertNotEquals(char unexpected, @Nullable Character actual)
Assert that |
| public static void | assertNotEquals(@Nullable Character unexpected, char actual)
Assert that |
| public static void | assertNotEquals(@Nullable Character unexpected, @Nullable Character actual)
Assert that |
| public static void | assertNotEquals(char unexpected, char actual, @Nullable String message)
Assert that |
| public static void | assertNotEquals(char unexpected, @Nullable Character actual, @Nullable String message)
Assert that |
| public static void | assertNotEquals(@Nullable Character unexpected, char actual, @Nullable String message)
Assert that |
| public static void | |
| public static void | assertNotEquals(char unexpected, char actual, Supplier<@Nullable String> messageSupplier)
Assert that |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertNotEquals(@Nullable Object unexpected, @Nullable Object actual)
Assert that |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertNotSame(@Nullable Object unexpected, @Nullable Object actual)
Assert that the |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | |
| public static void | assertSame(@Nullable Object expected, @Nullable Object actual)
Assert that the |
| public static void | |
| public static void | |
| public static <T extends Throwable> T | assertThrows(Class<T> expectedType, Executable executable)
Assert that execution of the supplied |
| public static <T extends Throwable> T | assertThrows(Class<T> expectedType, Executable executable, @Nullable String message)
Assert that execution of the supplied |
| public static <T extends Throwable> T | assertThrows(Class<T> expectedType, Executable executable, Supplier<@Nullable String> messageSupplier)
Assert that execution of the supplied |
| public static <T extends Throwable> T | assertThrowsExactly(Class<T> expectedType, Executable executable)
Assert that execution of the supplied |
| public static <T extends Throwable> T | assertThrowsExactly(Class<T> expectedType, Executable executable, @Nullable String message)
Assert that execution of the supplied |
| public static <T extends Throwable> T | assertThrowsExactly(Class<T> expectedType, Executable executable, Supplier<@Nullable String> messageSupplier)
Assert that execution of the supplied |
| public static void | assertTimeout(Duration timeout, Executable executable)
Assert that execution of the supplied |
| public static void | assertTimeout(Duration timeout, Executable executable, @Nullable String message)
Assert that execution of the supplied |
| public static void | assertTimeout(Duration timeout, Executable executable, Supplier<@Nullable String> messageSupplier)
Assert that execution of the supplied |
| public static <T extends @Nullable Object> T | assertTimeout(Duration timeout, ThrowingSupplier<T> supplier)
Assert that execution of the supplied |
| public static <T extends @Nullable Object> T | assertTimeout(Duration timeout, ThrowingSupplier<T> supplier, @Nullable String message)
Assert that execution of the supplied |
| public static <T extends @Nullable Object> T | assertTimeout(Duration timeout, ThrowingSupplier<T> supplier, Supplier<@Nullable String> messageSupplier)
Assert that execution of the supplied |
| public static void | assertTimeoutPreemptively(Duration timeout, Executable executable)
Assert that execution of the supplied |
| public static void | assertTimeoutPreemptively(Duration timeout, Executable executable, @Nullable String message)
Assert that execution of the supplied |
| public static void | assertTimeoutPreemptively(Duration timeout, Executable executable, Supplier<@Nullable String> messageSupplier)
Assert that execution of the supplied |
| public static <T extends @Nullable Object> T | assertTimeoutPreemptively(Duration timeout, ThrowingSupplier<T> supplier)
Assert that execution of the supplied |
| public static <T extends @Nullable Object> T | assertTimeoutPreemptively(Duration timeout, ThrowingSupplier<T> supplier, @Nullable String message)
Assert that execution of the supplied |
| public static <T extends @Nullable Object> T | assertTimeoutPreemptively(Duration timeout, ThrowingSupplier<T> supplier, Supplier<@Nullable String> messageSupplier)
Assert that execution of the supplied |
| public static void | |
| public static void | assertTrue(boolean condition, Supplier<@Nullable String> messageSupplier)
Assert that the supplied |
| public static void | assertTrue(BooleanSupplier booleanSupplier)
Assert that the boolean condition supplied by |
| public static void | assertTrue(BooleanSupplier booleanSupplier, @Nullable String message)
Assert that the boolean condition supplied by |
| public static void | |
| public static void | assertTrue(BooleanSupplier booleanSupplier, Supplier<@Nullable String> messageSupplier)
Assert that the boolean condition supplied by |
| public static <V> V | |
| public static <V> V | |
| public static <V> V | |
| public static <V> V | |
| public static <V> V |