Deglans Dalpasso
Deglans Dalpasso

Reputation: 515

Maven don't execute junit test

I'm trying to test this project: https://github.com/deglans/jenktest but maven say that:

$ mvn clean install    
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/usr/share/maven/lib/guice.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] jenktest
[INFO] hello
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building jenktest 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ jenktest ---
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ jenktest ---
[INFO] Installing /documenti/deglans/Programs/IdeaProjects/jenktest/pom.xml to /home/deglans/.m2/repository/io/github/deglans/jenktest/0.0.1-SNAPSHOT/jenktest-0.0.1-SNAPSHOT.pom
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building hello 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hello ---
[INFO] Deleting /documenti/deglans/Programs/IdeaProjects/jenktest/hello/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hello ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ hello ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to /documenti/deglans/Programs/IdeaProjects/jenktest/hello/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ hello ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /documenti/deglans/Programs/IdeaProjects/jenktest/hello/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ hello ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /documenti/deglans/Programs/IdeaProjects/jenktest/hello/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hello ---
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ hello ---
[INFO] Building jar: /documenti/deglans/Programs/IdeaProjects/jenktest/hello/target/hello-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ hello ---
[INFO] Installing /documenti/deglans/Programs/IdeaProjects/jenktest/hello/target/hello-0.0.1-SNAPSHOT.jar to /home/deglans/.m2/repository/io/github/deglans/hello/0.0.1-SNAPSHOT/hello-0.0.1-SNAPSHOT.jar
[INFO] Installing /documenti/deglans/Programs/IdeaProjects/jenktest/hello/pom.xml to /home/deglans/.m2/repository/io/github/deglans/hello/0.0.1-SNAPSHOT/hello-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] jenktest ........................................... SUCCESS [  0.449 s]
[INFO] hello .............................................. SUCCESS [  1.715 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.360 s
[INFO] Finished at: 2017-12-16T11:41:59+01:00
[INFO] Final Memory: 14M/48M
[INFO] ------------------------------------------------------------------------

What is the warning and why maven completely skip the test phase?

The final purpose of this work is to test email jenkins feature, but for now I'm blocked by this problem...

Thanks

Upvotes: 2

Views: 737

Answers (1)

Mincong Huang
Mincong Huang

Reputation: 5552

Summary

You need to either rename GreetingTests.java to GreetingTest.java, or update your maven-surefire-plugin. Updating surefire plugin can provide better pattern for inclusions of tests. You can declare it in project's parent POM ./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/xsd/maven-4.0.0.xsd">
  <!-- ... -->

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.20.1</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

Detail

What is the warning and why maven completely skip the test phase?

Maven didn't skip the test phase. Maven unit tests are executed by maven-surefire-plugin, and it has been triggered correctly:

[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hello ---

You need to rename your test to GreetingTests.java to GreetingTest.java. Because the surefire-plugin:2.12.4 does not recognize pattern *Tests.java, as documented here:

By default, the plugin will automatically include all test classes with the following wildcard patterns:

  • "**/Test*.java" - includes all of its subdirectories and all java filenames that start with "Test".

  • "**/*Test.java" - includes all of its subdirectories and all java filenames that end with "Test".

  • "**/*TestCase.java" - includes all of its subdirectories and all java filenames that end with "TestCase".

Upvotes: 2

Related Questions