(Test Lifecycle) (Sample Unit Test)
(Test Lifecycle) (Sample Unit Test)
(Test Lifecycle) (Sample Unit Test)
{ TEST TYPES }
@AfterAll
// basic test
@Test
// repeat test 10x
@RepeatedTest(10) { ASSERTION TYPES }
// parameterize single value
@ParameterizedTest // check if x is true/false
@ValuesSource(doubles = {70.0, 80.0}) assertTrue(x);
void testName(Double param) { … } assertFalse(x);
// params from csv file, ignore header // check if array1 and array2
@ParameterizedTest // contain the same elements
@CsvFileSource( assertArrayEquals(array1, array2);
resources = "/diet-params.csv",
numLinesToSkip = 1 // check if doSth() throws
) // SampleExeception
void testName(Double par1, Double par2) Executable executable = () -> doSth();
assertThrows(
SampleException.class,
{ OTHER } executable
);
// nested class
@Nested // check multiple assertions
class InnerClass { … } assertAll(
() → assertEquals(expected1, actual1),
// display name () → assertEquals(expected2, actual2)
@DisplayName("Custom name") );