Java maven project, when building mvn verify package, tests are run as it should, when you try to mvn test (from the compiler or console) a line appears

[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ GreetTime --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ 

and it immediately goes to the end. It’s so that my tests are just skipped, I think that somewhere I haven’t indicated the path to the necessary folder. How to make the tests run with the command mvn test . Because in the future I will need to run tests at build (Travis CI), at the moment I just can not see the tests. With mvn test -Dtest=IntegrationTest everything works, but this option is not suitable. When specifying <testClassesDirectory>Greeting\target\test-classes</testClassesDirectory> I get no Tests to run error

pom.xml

 <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> <groupId>com.mavenTime</groupId> <artifactId>GreetTime</artifactId> <packaging>jar</packaging> <version>1.0</version> <name>GreetJar</name> <url>http://maven.apache.org</url> <properties> <log4j.version>1.2.12</log4j.version> </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.12.4</version> <configuration> <skipTests>false</skipTests> <excludes> <exclude>**/*IntegrationTest.java</exclude> </excludes> <testSourceDirectory>${project.build.testSourceDirectory}</testSourceDirectory> <reportsDirectory>Greeting\target\surefire-reports</reportsDirectory> </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> <include>**/*IntegrationTest.java</include> <include>**/*IntegrationTest*.java</include> </includes> <testSourceDirectory>Greeting\target\surefire-reports</testSourceDirectory> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib</classpathPrefix> <mainClass>Main</mainClass> </manifest> </archive> </configuration> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> <configuration> <archive> <manifest> <mainClass>Main</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>${jdk.version}</source> <target>${jdk.version}</target> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> <exclusions> <exclusion> <groupId>org.testng</groupId> <artifactId>testng</artifactId> </exclusion> </exclusions> </dependency> </dependencies> </project> 
  • When creating a maven project, 2 sub-directories are created, main/java and test/java and when you run a package , tes t or install mvn, it scans the test toolbox for tests and runs them. And no additional manipulations with the pom-a configuration are required - GVArt Sept
  • What then can be the problem? PRi mvn verify package everything works, nothing happens with the maven test (Maybe something extra in my pom? - AlexanderBogomaz
  • Try to delete all configs associated with the tests from pom-a and run it again. And yes, why is the path to the tests specified on the targer directory? - GVArt

1 answer 1

Try adding all tests to the src / test / java package, the test classes themselves must either start with Test or end with Test , for example TestMain or MainTest . Plugin for mavena:

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.19.1</version> <configuration> <skipTests>false</skipTests> </configuration> </plugin> 
  • The test class is in the src / test / java folder, this plug-in is, the word TEST is present in the class, I think to look for extra plug-ins and delete, it may conflict. - AlexanderBogomaz
  • Try to set only <skipTests>false</skipTests> in the settings of the plugin in <configuration> <skipTests>false</skipTests> - Sep
  • I would give you 100 pluses, but I am deprived of such an opportunity !!! She is LIFE !!!!! thanks !!!!!!!!!!!! - AlexanderBogomaz