Test Overview
This test checks how a JUnit extension customizes test behavior by adding a setup step before each test and verifying it runs correctly.
This test checks how a JUnit extension customizes test behavior by adding a setup step before each test and verifying it runs correctly.
import org.junit.jupiter.api.extension.BeforeEachCallback; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertTrue; class CustomSetupExtension implements BeforeEachCallback { boolean setupDone = false; @Override public void beforeEach(ExtensionContext context) { setupDone = true; // Custom setup logic } } public class ExtensionBehaviorTest { @RegisterExtension static CustomSetupExtension extension = new CustomSetupExtension(); @Test void testSetupIsDone() { assertTrue(extension.setupDone, "Setup should be done before test"); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | JUnit test runner starts the ExtensionBehaviorTest class | Test class loaded, extension registered | - | PASS |
| 2 | JUnit calls beforeEach method of CustomSetupExtension before testSetupIsDone | Extension's setupDone flag set to true | - | PASS |
| 3 | JUnit runs testSetupIsDone method | Test method executing with extension.setupDone == true | assertTrue(extension.setupDone) verifies setupDone is true | PASS |
| 4 | JUnit completes test and reports result | Test passed successfully | - | PASS |