@SpringJUnitConfig static class TestCase { @BeforeEach void beforeEach(@Autowired ApplicationContext context) { } @RepeatedTest(NUM_TESTS) void repeatedTest(@Autowired ApplicationContext context) { } @AfterEach void afterEach(@Autowired ApplicationContext context) { } @Configuration static class Config { } }
@SpringJUnitConfig(TestConfig.class) interface GenericComicCharactersInterfaceDefaultMethodsTests<C extends Character> {
@SpringJUnitConfig(TestConfig.class) class SpringExtensionParameterizedTests {
@FailingTestCase @SpringJUnitConfig(DatabaseConfig.class) @Transactional static class FailingBeforeTransactionTestCase { @Test void testNothing() { } @BeforeTransaction void beforeTransaction() { fail("always failing beforeTransaction()"); } }
@FailingTestCase @SpringJUnitConfig(DatabaseConfig.class) @Transactional static class FailingAfterTransactionTestCase { @Test void testNothing() { } @AfterTransaction void afterTransaction() { fail("always failing afterTransaction()"); } }
@Nested @SpringJUnitConfig(NestedConfig.class) class QualifiedConstructorParameterTests { final String bar; QualifiedConstructorParameterTests(TestInfo testInfo, @Qualifier("bar") String s) { this.bar = s; } @Test void nestedTest() throws Exception { assertEquals("foo", foo); assertEquals("bar", bar); } }
@Nested @SpringJUnitConfig(NestedConfig.class) class AutowiredConstructorParameterTests { final String bar; AutowiredConstructorParameterTests(@Autowired String bar) { this.bar = bar; } @Test void nestedTest() throws Exception { assertEquals("foo", foo); assertEquals("bar", bar); } }
@Nested @SpringJUnitConfig(NestedConfig.class) class NestedTests { @Autowired String bar; @Test void nestedTest() throws Exception { // In contrast to nested test classes running in JUnit 4, the foo // field in the outer instance should have been injected from the // test ApplicationContext for the outer instance. assertEquals("foo", foo); assertEquals("bar", bar); } }
@Nested @SpringJUnitConfig(NestedConfig.class) class AutowiredConstructorTests { final String bar; @Autowired AutowiredConstructorTests(String bar) { this.bar = bar; } @Test void nestedTest() throws Exception { assertEquals("foo", foo); assertEquals("bar", bar); } }
@SpringJUnitConfig(TestConfig.class) abstract class GenericComicCharactersTests<T extends Character> {
@SpringJUnitConfig(TopLevelConfig.class) class NestedTestsWithSpringAndJUnitJupiterTests {
@Nested @SpringJUnitConfig(NestedConfig.class) class SpelConstructorParameterTests { final String bar; final int answer; SpelConstructorParameterTests(@Autowired String bar, TestInfo testInfo, @Value("#{ 6 * 7 }") int answer) { this.bar = bar; this.answer = answer; } @Test void nestedTest() throws Exception { assertEquals("foo", foo); assertEquals("bar", bar); assertEquals(42, answer); } }
@Nested @SpringJUnitConfig(PopulatedSchemaDatabaseConfig.class) @Transactional class NestedTests { @Autowired JdbcTemplate jdbcTemplate; @BeforeTransaction @AfterTransaction void checkInitialDatabaseState() { assertEquals(0, countRowsInTable("user")); } @Test @Sql("/org/springframework/test/context/jdbc/data.sql") void nestedSqlScripts() { assertEquals(1, countRowsInTable("user")); } private int countRowsInTable(String tableName) { return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName); } }
@SpringJUnitConfig(TestConfig.class) @DisplayName("@SpringJUnitConfig Tests") class ComposedSpringExtensionTests {
@SpringJUnitConfig(Config.class) @Nested @DisabledIf("true") class DisabledIfOnClassTests { @Test void foo() { fail("This test must be disabled"); } @Test @DisabledIf("false") void bar() { fail("This test must be disabled due to class-level condition"); } }
@SpringJUnitConfig(Config.class) @Nested @EnabledIf("false") class EnabledIfOnClassTests { @Test void foo() { fail("This test must be disabled"); } @Test @EnabledIf("true") void bar() { fail("This test must be disabled due to class-level condition"); } }
@SpringJUnitConfig(TestConfig.class) @TestPropertySource(properties = "enigma = 42") class SpringJUnitJupiterAutowiredConstructorInjectionTests {
@SpringJUnitConfig(PopulatedSchemaDatabaseConfig.class) @Transactional @TestInstance(Lifecycle.PER_CLASS)
@SpringJUnitConfig(TestConfig.class) @TestPropertySource(properties = "enigma = 42") class SpringJUnitJupiterConstructorInjectionTests {
@SpringJUnitConfig(Config.class) @TestPropertySource(properties = "foo = true") @Nested