Recall & Review
beginner
What is a nested test class in JUnit?A nested test class is a static or non-static inner class inside a test class used to group related tests together for better organization and readability.Click to reveal answer
intermediate
How does the lifecycle of a nested test class differ from the outer test class in JUnit?Each nested test class has its own lifecycle: its @BeforeAll and @AfterAll methods run before and after all tests in that nested class, separate from the outer class lifecycle.Click to reveal answer
beginner
Which JUnit annotation is used to define a nested test class?
The @Nested annotation is used to mark a class inside a test class as a nested test class.Click to reveal answer
intermediate
Can @BeforeAll methods in nested classes be non-static in JUnit 5?
Yes, in nested test classes, @BeforeAll and @AfterAll methods can be non-static because JUnit creates a new instance of the nested class for running tests.Click to reveal answer
beginner
Why use nested test classes in JUnit?
Nested test classes help organize tests into logical groups, making tests easier to read and maintain, especially when testing different scenarios or states of the same class.
Click to reveal answer
Which annotation marks a nested test class in JUnit?
✗ Incorrect
The @Nested annotation is the correct way to mark a nested test class in JUnit.
In JUnit, when are @BeforeAll methods in a nested class executed?
✗ Incorrect
@BeforeAll methods in a nested class run once before all tests in that nested class.
Can @BeforeAll methods in nested classes be non-static in JUnit 5?
✗ Incorrect
JUnit 5 allows non-static @BeforeAll in nested classes because it creates a new instance of the nested class.
What is the main benefit of using nested test classes?
✗ Incorrect
Nested test classes help organize tests logically, improving readability and maintenance.
Which lifecycle methods are scoped to a nested test class?
✗ Incorrect
All lifecycle methods (@BeforeAll, @AfterAll, @BeforeEach, @AfterEach) can be defined and scoped within a nested test class.
Explain how the lifecycle of nested test classes works in JUnit and how it differs from the outer test class lifecycle.
Think about how setup and teardown happen inside nested classes compared to the outer class.
You got /4 concepts.
Describe the advantages of using nested test classes in organizing your JUnit tests.
Consider how nested classes help when testing multiple states or behaviors of the same class.
You got /4 concepts.