LearnThatStack Ace your next interview
JUnit 5 · question
Q.04 of 22

What are the main annotations in JUnit 5?

beginner
← All JUnit 5 questions
Re-explain

Core Test Annotations:

  • @Test: Marks a method as a test method
  • @ParameterizedTest: Indicates a parameterized test
  • @RepeatedTest: Repeats test execution multiple times
  • @TestFactory: Defines a method for dynamic test generation

Lifecycle Annotations:

  • @BeforeEach: Executed before each test method
  • @AfterEach: Executed after each test method
  • @BeforeAll: Executed once before all test methods (static)
  • @AfterAll: Executed once after all test methods (static)

Organization Annotations:

  • @DisplayName: Provides custom display name for tests
  • @Nested: Creates nested test classes for better organization
  • @Tag: Tags tests for filtering and grouping
  • @Disabled: Disables a test method or class

Example Usage:

@DisplayName("Calculator Tests")
class CalculatorTest {
    
    @BeforeEach
    void setUp() {
        calculator = new Calculator();
    }
    
    @Test
    @DisplayName("Should add two positive numbers correctly")
    void testAddition() {
        assertEquals(5, calculator.add(2, 3));
    }
    
    @Nested
    @DisplayName("Division Tests")
    class DivisionTests {
        
        @Test
        void testValidDivision() {
            assertEquals(2, calculator.divide(10, 5));
        }
        
        @Test
        @Disabled("Division by zero behavior under review")
        void testDivisionByZero() {
            // Test implementation
        }
    }
}
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

The model's verdict: “

The interactive diagram is below the answer - jump to diagram ↓

This answer is explained by a shared concept diagram - open

Tailored explanation · switch back to · ·
Point the redraw:
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the JUnit 5 cheatsheet.

← Back to all JUnit 5 questions
Pro · $10/mo

19 of 22 JUnit 5 answers are gated.

Full answers, code samples, AI explanations - simpler, deeper, or as an interactive diagram. Cancel anytime.

  • Full answers + code
  • AI explain - simpler, deeper, or visualized
  • 1,000 AI credits / month
  • Cancel anytime