Complete the code to annotate a method that runs once before all tests in a JUnit 5 test class.
@[1] static void setupAll() { System.out.println("Runs once before all tests"); }
The @BeforeAll annotation marks a method to run once before all tests in the class.
Complete the code to annotate a method that runs before each test method in JUnit 5.
@[1] void setup() { System.out.println("Runs before each test"); }
The @BeforeEach annotation marks a method to run before each test method.
Fix the error in the code to correctly annotate a method that runs once after all tests in JUnit 5.
@[1] static void tearDownAll() { System.out.println("Runs once after all tests"); }
The @AfterAll annotation marks a method to run once after all tests. The method must be static.
Fill both blanks to create a JUnit 5 test class with methods that run before all tests and after each test.
import org.junit.jupiter.api.*; public class ExampleTest { @[1] static void initAll() { System.out.println("Init before all tests"); } @[2] void tearDown() { System.out.println("Cleanup after each test"); } }
@BeforeAll runs once before all tests, and @AfterEach runs after each test method.
Fill all three blanks to create a JUnit 5 test class with methods that run before each test, after each test, and once after all tests.
import org.junit.jupiter.api.*; public class LifecycleTest { @[1] void setup() { System.out.println("Before each test"); } @[2] void cleanup() { System.out.println("After each test"); } @[3] static void finish() { System.out.println("After all tests"); } }
@BeforeEach runs before each test, @AfterEach runs after each test, and @AfterAll runs once after all tests (method must be static).