This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @TestMethodOrder(OrderAnnotation.class) | |
| public class TestTempDir { | |
| @TempDir | |
| static Path classTempDir; | |
| @TempDir | |
| static File classTempDirAsFile; | |
| @Test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class TestKitExample { | |
| @Test | |
| void failIfTestsAreSkipped() { | |
| Events testEvents = EngineTestKit | |
| .engine("junit-jupiter") | |
| .selectors(selectClass(TestKitSubject.class)) | |
| .execute() | |
| .tests(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class TestKitSubject { | |
| @Test | |
| public void fakeRunningTest() { | |
| } | |
| @Test | |
| @Disabled | |
| public void fakeDisabledTest() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class TestExtensionOrdering { | |
| @RegisterExtension | |
| @Order(3) | |
| static ExampleJUnit5Extension extensionA = new ExampleJUnit5Extension("A"); | |
| @RegisterExtension | |
| @Order(2) | |
| static ExampleJUnit5Extension extensionB = new ExampleJUnit5Extension("B"); | |
| @RegisterExtension | |
| @Order(1) | |
| static ExampleJUnit5Extension extensionC = new ExampleJUnit5Extension("C"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <dependency> | |
| <groupId>org.junit.platform</groupId> | |
| <artifactId>junit-platform-testkit</artifactId> | |
| <scope>test</scope> | |
| </dependency> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class TestHandleExceptionsJUnit4 { | |
| @Rule | |
| public ExpectedException expectedException = ExpectedException.none(); | |
| @Test(expected = SpecificException.class) | |
| public void testSpecificExceptionHandling() throws SpecificException { | |
| onlyThrowsExceptions(); | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class TestHandleExceptionsJUnit5 { | |
| @Test | |
| public void testExceptionHandling() { | |
| Exception e = assertThrows(SpecificException.class, () -> onlyThrowsExceptions()); | |
| assertEquals("An exception was thrown!", e.getMessage()); | |
| } | |
| @Test | |
| public void testExceptionHandlingFailWrongExceptionType() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @ExtendWith(MockitoExtension.class) | |
| public class TestUserService { | |
| @Nested | |
| class TestWithMethodInjection { | |
| @Test | |
| public void testAddNewUserAndAddress(@Mock UserDao userDao, @Mock AddressDao addressDao) { | |
| when(userDao.addNewUser(any())).thenCallRealMethod(); | |
| when(addressDao.addNewAddress(any())).thenCallRealMethod(); | |
| UserService service = new UserService(userDao, addressDao); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @SpringJUnitConfig | |
| @ContextConfiguration(classes = { StormTrackerApplication.class }, initializers = ITStormRepo.Initializer.class) | |
| @TestPropertySource("classpath:application.properties") | |
| @TestMethodOrder(OrderAnnotation.class) | |
| public class ITStormRepo { | |
| public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { | |
| @Override | |
| public void initialize(ConfigurableApplicationContext applicationContext) { | |
| TestPropertyValues.of("spring.datasource.url=jdbc:tc:postgresql:11.2://arbitrary/arbitrary", // |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.ibm.developer.stormtracker; | |
| import static org.assertj.core.api.Assertions.assertThat; | |
| import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; | |
| import org.junit.jupiter.api.Order; | |
| import org.junit.jupiter.api.Test; | |
| import org.junit.jupiter.api.TestMethodOrder; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.boot.test.util.TestPropertyValues; |