Created
August 31, 2016 11:03
-
-
Save ahrytsiuk/c5289a63c1ea83557fcb1064ec51712d to your computer and use it in GitHub Desktop.
Code sample showing how to implement before all and after all callbacks for nested test classes.
This file contains 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
import lombok.extern.slf4j.Slf4j; | |
import org.junit.jupiter.api.*; | |
@Slf4j | |
public class OuterTest { | |
@BeforeAll | |
static void outerInitAll() { | |
log.info("OUTER: Initializing external resources..."); | |
} | |
@BeforeEach | |
void outerInit() { | |
log.info("OUTER: Initializing mock objects..."); | |
} | |
@Test | |
void outerTest() { | |
log.info("OUTER: executing test"); | |
} | |
@Nested | |
class InnerTest extends InnerInitializer { | |
@BeforeEach | |
void innerInit() { | |
log.info("INNER: Initializing mock objects..."); | |
} | |
@Test | |
void innerTest() { | |
log.info("INNER: executing test"); | |
} | |
@AfterEach | |
void innerTearDown() { | |
log.info("INNER: Tearing down..."); | |
} | |
} | |
static class InnerInitializer { | |
@BeforeAll | |
static void innerInitAll() { | |
log.info("INNER: Initializing external resources..."); | |
} | |
@AfterAll | |
static void innerTearDownAll() { | |
log.info("INNER: Freeing external resources..."); | |
} | |
} | |
@AfterEach | |
void outerTearDown() { | |
log.info("OUTER: Tearing down..."); | |
} | |
@AfterAll | |
static void outerTearDownAll() { | |
log.info("OUTER: Freeing external resources..."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment