- @Test
- @DisplayName(“we can change method name”)
- @Disabled - obmit this method
- @RepeatedTest(n) - test execute n times
- @Tag(tag1, tag2) - will use execute test functions based on tag exist
AssertEqual functions:
- assertEquals(expected, actual);
- assertArrayEquals(expectedArray, actualArray);
- assertIterableEquals(expectedArray, actualArray);
- assertTrue(boolean condition)
- void assertFalse(boolean condition)
- void assertNotNull(Object object)
- void assertNull(Object object)
- void assertSame(object1, object2)
- void assertNotSame(object1, object2)
#handle exception
assertThrows(ArithmeticException.class, ()->className.functionName, “test message to display”);
Test Lifecycle:
- @Before - executed before each test
- @BeforeClass - execute it only once before running all tests. should be static
- @BeforeEach and @BeforeAll are the JUnit 5 equivalents of @Before and @BeforeClass
Test instance:
- @TestInstance(TestInstance.Lifecycle.PER_CLASS) - Object is same for whole class
- @TestInstance(TestInstance.Lifecycle.PER_METHOD) - each function each object will get created
Conditional Execution:
- @EnabledOnOs({OS.LINUX, OS.WINDOWS})
- @DisabledOnOs(OS.WINDOWS)
- @EnabledOnJre(JRE.JAVA_9)
- @EnabledIfSystemProperty(named = “java.vm.name”, matches = “.OpenJDK.”)
- @EnabledIfEnvironmentVariable(named = “PROCESSOR_IDENTIFIER”, matches = “.Intel64 Family 6.”)
AssertAll:
assertAll( ()->assertEqual(expected,actual),()->assertEqual(expected,actual)); #testcase inside testcase
NOte: put @Nested before a nested class, to acheive nested testcase