So when I try to run some tests on Maven , tests can't find Junit tests , but when I run on VSCode , the tests are running . I tried to look some solution on Stack Overflow , but nothing similar to my issue The directory structure:
/my_program/pom.xml
/my_program/src/main/java/GestionQuality.java
/my_program/src/test/java/GestionQualiteTest.java
The GestionQualite.java :
import java.util.Map;
import java.util.*;
public class GestionQualite {
protected Map<String, String> map = new HashMap<String, String>();
/**
* Return the quality of a command from 1 to 5
* @param command the command
* @return the quality of the command
*/
public String make_quality(String command){
map.put("command","2");
if (map.containsKey(command)){
return map.get(command);
}
else {
return "qualite non renseigne";
}
}
}
the GestionQualityTest.java contains :
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class GestionQualiteTest {
/**
* Check if the quality is empty
*
* @result an error if the quality level is empty
*
*/
GestionQualite gestionqualite= new GestionQualite();
@Test
public void CheckQualityFailTest() {
String command = "";
assertEquals(gestionqualite.make_quality(command),"qualite non renseigne");
}
/**
* Check if the quality isnt empty for a command
*
* @result the quality of a command
*
*/
@Test
public void CheckQualitySucceedTest() {
assertEquals(gestionqualite.make_quality("command"),"2");
}
}
My pom.xml contains this :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- =============================================================== -->
<!-- Informations du projet -->
<!-- =============================================================== -->
<!-- ===== Informations Maven ===== -->
<groupId>oasis.goodDev</groupId>
<artifactId>preudhomme</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<!-- ===== Informations générales ===== -->
<name>Preud Homme</name>
<description> Future ERP de la banque preudhomme</description>
<url>http://www.exemple.org/mon-appli</url>
<!-- ===== Organisation ===== -->
<organization>
<name>Good Oasis Dev</name>
<url>http://www.exemple.org/</url>
</organization>
<!-- ===== Informations des dependances ===== -->
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- ===== Information du build ===== -->
<build>
<finalName>preudhomme</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.1</version>
<configuration>
<port>9000</port>
<tempWebappDirectory>${basedir}/target/site</tempWebappDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version>
<executions>
<execution>
<id>enforce-no-snapshots</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireReleaseDeps>
<message>No Snapshots Allowed!</message>
</requireReleaseDeps>
</rules>
<fail>true</fail>
</configuration>
</execution>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>[3.0.0,)</version>
</requireMavenVersion>
</rules>
<fail>true</fail>
</configuration>
</execution>
<execution>
<id>enforce-java</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>[11,12)</version>
</requireJavaVersion>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-help-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>print-profile</id>
<phase>compile</phase>
<goals>
<goal>active-profiles</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- ===== Informations du reporting ===== -->
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.9</version>
</plugin>
</plugins>
</reporting>
<profiles>
<!-- Profil local -->
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<!-- Profil pour les tests -->
<profile>
<id>test</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>test</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- Profil pour la production-->
<profile>
<id>prod</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
</profile>
</profiles>
</project>