Test Overview
This test uses JUnit's @EnabledIf annotation to run a test only when a custom condition method returns true. It verifies that the condition controls test execution.
This test uses JUnit's @EnabledIf annotation to run a test only when a custom condition method returns true. It verifies that the condition controls test execution.
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIf; import static org.junit.jupiter.api.Assertions.assertTrue; public class CustomConditionTest { @Test @EnabledIf("customCondition") void testRunsOnlyIfConditionTrue() { assertTrue(true, "This test runs only if customCondition returns true"); } boolean customCondition() { // Custom logic, here simply returns true return true; } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | JUnit test runner starts and scans for tests | Test class CustomConditionTest is loaded | - | PASS |
| 2 | JUnit evaluates @EnabledIf annotation by calling customCondition() | customCondition() method returns true | Check if customCondition() returns true to enable test | PASS |
| 3 | JUnit executes testRunsOnlyIfConditionTrue() test method | Inside test method, assertion assertTrue(true) runs | assertTrue(true) verifies condition is true | PASS |
| 4 | Test completes successfully | Test result recorded as passed | - | PASS |