Test Overview
This test uses JUnit's @EnumSource to run the same test method for each value of an enum. It verifies that the enum values are correctly passed and processed in the test.
This test uses JUnit's @EnumSource to run the same test method for each value of an enum. It verifies that the enum values are correctly passed and processed in the test.
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; import static org.junit.jupiter.api.Assertions.*; public class TrafficLightTest { enum TrafficLight { RED, YELLOW, GREEN } @ParameterizedTest @EnumSource(TrafficLight.class) void testTrafficLightEnum(TrafficLight light) { assertNotNull(light); assertTrue(light == TrafficLight.RED || light == TrafficLight.YELLOW || light == TrafficLight.GREEN); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts and identifies the parameterized test with @EnumSource for TrafficLight enum | JUnit test environment ready to run tests | - | PASS |
| 2 | Test method 'testTrafficLightEnum' runs with parameter TrafficLight.RED | Test method executing with parameter RED | assertNotNull(RED) and assertTrue(RED is one of RED, YELLOW, GREEN) | PASS |
| 3 | Test method 'testTrafficLightEnum' runs with parameter TrafficLight.YELLOW | Test method executing with parameter YELLOW | assertNotNull(YELLOW) and assertTrue(YELLOW is one of RED, YELLOW, GREEN) | PASS |
| 4 | Test method 'testTrafficLightEnum' runs with parameter TrafficLight.GREEN | Test method executing with parameter GREEN | assertNotNull(GREEN) and assertTrue(GREEN is one of RED, YELLOW, GREEN) | PASS |
| 5 | All enum values tested, test suite completes | All parameterized tests passed | - | PASS |