Friday, December 16, 2022

POM update to run JUNIT Tests when we do "mvn test"

 Some times:


unit tests in test files under src/test wont run when we do. "mvn test" command


Some observations to check  is:

- Few plugins considers file name is Test

- Practise to name function name prefix or suffix by Test

- Another important thing is maven configuration (For Junit 4) add below info


<dependencies>
    <dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.0</version>
</plugin>
</plugins>
</build>

Refer: https://junit.org/junit5/docs/current/user-guide/#running-tests-build-maven

No comments:

Post a Comment