Recall & Review
beginner
What is the purpose of the @BeforeAll annotation in JUnit?
The @BeforeAll method runs once before all tests in the class. It is used to set up shared resources needed for all tests.
Click to reveal answer
beginner
In what order do JUnit lifecycle methods execute around each test?
For each test, JUnit runs @BeforeEach, then the test method, then @AfterEach.
Click to reveal answer
beginner
When is the @AfterAll method executed in JUnit?
The @AfterAll method runs once after all tests in the class have finished. It is used to clean up shared resources.Click to reveal answer
beginner
True or False: @BeforeEach methods run before every test method in JUnit.
True. @BeforeEach methods run before each test method to prepare the test environment.
Click to reveal answer
intermediate
What is the difference between @BeforeAll and @BeforeEach in JUnit?
@BeforeAll runs once before all tests; @BeforeEach runs before each individual test method.
Click to reveal answer
Which JUnit annotation runs a method once before all tests in a class?
✗ Incorrect
@BeforeAll runs once before all tests to set up shared resources.
What is the correct order of execution for lifecycle methods around a single test?
✗ Incorrect
For each test, JUnit runs @BeforeEach, then the test, then @AfterEach.
When does the @AfterAll method run in JUnit?
✗ Incorrect
@AfterAll runs once after all tests to clean up shared resources.
Which annotation is used to run code before every test method?
✗ Incorrect
@BeforeEach runs before each test method to prepare the test environment.
What is the main difference between @BeforeAll and @BeforeEach?
✗ Incorrect
@BeforeAll runs once before all tests; @BeforeEach runs before each individual test.
Explain the execution order of JUnit lifecycle methods when running multiple tests in a class.
Think about setup and teardown steps that happen once versus those that happen for every test.
You got /5 concepts.
Describe the purpose of each JUnit lifecycle annotation: @BeforeAll, @BeforeEach, @AfterEach, and @AfterAll.
Consider when each method runs relative to the tests.
You got /4 concepts.