Test Overview
This test checks if the JUnit dependency is correctly set up in a Maven project by running a simple test case that asserts basic math.
This test checks if the JUnit dependency is correctly set up in a Maven project by running a simple test case that asserts basic math.
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class SimpleMathTest { @Test public void testAddition() { int sum = 2 + 3; assertEquals(5, sum, "2 + 3 should equal 5"); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Maven builds the project and downloads dependencies | Maven resolves junit-jupiter-api and junit-jupiter-engine dependencies | — | PASS |
| 2 | JUnit test runner starts and loads SimpleMathTest class | Test class loaded, test methods discovered | — | PASS |
| 3 | JUnit executes testAddition method | Inside testAddition, sum calculated as 5 | assertEquals(5, sum) verifies sum is 5 | PASS |
| 4 | JUnit reports test result | Test passed with no failures or errors | Test result is PASS | PASS |
pom.xml file of a Maven project?pom.xml with scope set to test?org.junit.jupiter and junit-jupiter.test to limit usage to testing phase.pom.xml snippet, what will happen when you run mvn test?
<dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.9.2</version> <scope>test</scope> </dependency>
pom.xml but your tests fail with ClassNotFoundException for JUnit classes. What is the likely problem?
<dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.9.2</version> </dependency>
junit-jupiter which bundles API and engine.pom.xml?junit-jupiter artifact includes API and engine for tests.scope to test ensures dependency is used only during testing.Pass the test and this pattern moves unknown