Recall & Review
beginner
What is the purpose of using @Nested inner classes in JUnit?
They help organize tests into logical groups inside a test class, making tests easier to read and maintain.
Click to reveal answer
beginner
How do you declare a nested test class in JUnit 5?By annotating a non-static inner class with @Nested inside a test class.Click to reveal answer
intermediate
Can @Nested classes access instance variables of the outer test class?
Yes, nested classes can access instance variables and methods of the outer test class, allowing shared setup.
Click to reveal answer
intermediate
What is a benefit of using @Nested classes compared to separate test classes?
They keep related tests grouped together in one file, improving readability and reducing duplication.
Click to reveal answer
intermediate
Does @Nested support lifecycle methods like @BeforeEach inside the nested class?
Yes, you can use lifecycle annotations like @BeforeEach and @AfterEach inside @Nested classes for setup and cleanup.
Click to reveal answer
What annotation marks an inner class as a nested test class in JUnit 5?
✗ Incorrect
The @Nested annotation is used to declare an inner class as a nested test class in JUnit 5.
Which of the following is a key benefit of using @Nested classes?
✗ Incorrect
Nested classes help organize related tests together, improving code structure and readability.
Can @Nested classes have their own @BeforeEach methods?
✗ Incorrect
Nested classes can define their own lifecycle methods like @BeforeEach to set up tests.
What is the visibility requirement for a @Nested class in JUnit?
✗ Incorrect
A @Nested class must be a non-static inner class with at least package-private visibility.
Which statement is true about @Nested classes accessing outer class members?
✗ Incorrect
Nested classes have access to instance variables and methods of their outer class.
Explain how @Nested inner classes improve test organization in JUnit.
Think about how grouping tests helps keep code clean and easier to understand.
You got /4 concepts.
Describe the rules and best practices for writing @Nested classes in JUnit.
Consider class structure, annotations, and lifecycle support.
You got /4 concepts.