Maven don't execute junit test - maven

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

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".

Related

Why failed to compile pentaho-kettle-9.0.0.2-R?

Why dose the release build fail? Pentaho-kettle-9.0.0.3-R is same problem.
Environmental information:
maven version 3
jdk 11
mvn clean install -Dmaven.test.skip=true
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # kettle-core ---
[INFO]
[INFO] --- build-helper-maven-plugin:3.0.0:parse-version (set-doc-version-property) # kettle-core ---
[INFO]
[INFO] --- build-helper-maven-plugin:3.0.0:rootlocation (set-root-dir-property) # kettle-core ---
[INFO]
[INFO] --- license-helper-maven-plugin:1.27:check-license (check-license) # kettle-core ---
[INFO] Effective license file is [/usr/src/app/src/pentaho-kettle-9.0.0.2-R/LICENSE.txt]
[INFO]
[INFO] --- iterator-maven-plugin:0.5.1:iterator (javascript-dependencies_unpack-dependencies) # kettle-core ---
[INFO] ------ (dummy) org.apache.maven.plugins:maven-dependency-plugin:3.1.0:unpack-dependencies
[INFO]
[INFO] --- build-helper-maven-plugin:3.0.0:add-resource (add-filtered-resources) # kettle-core ---
[INFO]
[INFO] --- license-helper-maven-plugin:1.27:bundle (bundle-license) # kettle-core ---
[INFO] License file [/usr/src/app/src/pentaho-kettle-9.0.0.2-R/LICENSE.txt] will be added to [META-INF/LICENSE.txt]
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) # kettle-core ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 90 resources
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) # kettle-core ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 398 source files to /usr/src/app/src/pentaho-kettle-9.0.0.2-R/core/target/classes
[INFO] /usr/src/app/src/pentaho-kettle-9.0.0.2-R/core/src/main/java/org/pentaho/di/version/BuildVersion.java: Some input files use or override a deprecated API.
[INFO] /usr/src/app/src/pentaho-kettle-9.0.0.2-R/core/src/main/java/org/pentaho/di/version/BuildVersion.java: Recompile with -Xlint:deprecation for details.
[INFO] /usr/src/app/src/pentaho-kettle-9.0.0.2-R/core/src/main/java/org/pentaho/di/core/plugins/SupplementalPlugin.java: Some input files use unchecked or unsafe operations.
[INFO] /usr/src/app/src/pentaho-kettle-9.0.0.2-R/core/src/main/java/org/pentaho/di/core/plugins/SupplementalPlugin.java: Recompile with -Xlint:unchecked for details.
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /usr/src/app/src/pentaho-kettle-9.0.0.2-R/core/src/main/java/org/pentaho/di/core/Result.java:[32,33] package javax.xml.bind.annotation does not exist
[ERROR] /usr/src/app/src/pentaho-kettle-9.0.0.2-R/core/src/main/java/org/pentaho/di/core/Result.java:[65,2] cannot find symbol
symbol: class XmlRootElement
[INFO] 2 errors
Who can help me?
Look at main pom.xml like
https://github.com/pentaho/pentaho-kettle/blob/master/pom.xml
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
Use jdk8.
package javax.xml.bind.annotation does not exist because if I ain't mistaken, it is moved to jee with removal from jdk core since jdk9

Maven surefire plugin doesn't run our Unit test case

Apache Maven 3.5.2 - the pom.xml doesn't declare the surefire plugin explicitly, but the effective pom.xml shows 2.18.1
When I run 'mvn test' - it ends successfully, it doesn't say that it can't find any test cases, but there is no trace of the test cases. This is all I see:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building SpreadSheetUploadWeb 1.0
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.fasterxml.jackson.core:jackson-databind:jar:1.9.10 is missing, no dependency information available
[WARNING] The POM for com.fasterxml.jackson.core:jackson-annotations:jar:1.9.10 is missing, no dependency information available
[WARNING] The POM for com.fasterxml.jackson.core:jackson-core:jar:1.9.10 is missing, no dependency information available
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # SpreadSheetUploadWeb ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 22 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # SpreadSheetUploadWeb ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # SpreadSheetUploadWeb ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 5 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # SpreadSheetUploadWeb ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) # SpreadSheetUploadWeb ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
My pom.xml has jar specified, and my test case is in:
c:/SpreadSheetUploadWeb/src/test/java/com/ibm/cio/cloud/cost/spreadsheet/dao/UnitTestJdbcCostSpreadsheetDAO.java
It works perfectly when I run test explicitly like this:
mvn surefire:test -Dtest=UnitTestJdbcCostSpreadsheetDAO.java
Why won't it run when I just run: mvn test ?
By default surefire search for files following this patterns:
**/Test*.java
**/*Test.java
**/*Tests.java
**/*TestCase.java
http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html

Jenkins jobs says build success but scripts in testng.xml are not executing

I created a sample maven project and i have a class with below code
package Basics;
import org.testng.annotations.Test;
public class Second {
#Test
public void jenkinstest()
{
System.out.println("Jenkins test sample");
}
}
and below is the testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Test">
<classes>
<class name="Basics.Second"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
I create a maven project in Jenkins and provided above project pom.xml path in Root pom field, then when i click on "BuildNow", Jenkins jobs says build success but scripts in testng.xml are not executing
Below is the output from Jenkins
Started by user anonymous
Building in workspace C:\Users\manchukondaanil_k\.jenkins\workspace\JenkinsRun
Parsing POMs
[Guru99] $ "C:\Program Files\Java\jdk1.8.0_73/bin/java" -cp C:\Users\manchukondaanil_k\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven31-agent-1.5.jar;D:\Selenium_Softwares\apache-maven-3.2.5\boot\plexus-classworlds-2.5.2.jar;D:\Selenium_Softwares\apache-maven-3.2.5/conf/logging jenkins.maven3.agent.Maven31Main D:\Selenium_Softwares\apache-maven-3.2.5 C:\Users\manchukondaanil_k\.jenkins\war\WEB-INF\lib\remoting-2.56.jar C:\Users\manchukondaanil_k\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven31-interceptor-1.5.jar C:\Users\manchukondaanil_k\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven3-interceptor-commons-1.5.jar 52811
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven: -B -f D:\SeleniumProjects\Guru99Project\Guru99\pom.xml clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Guru99 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # Guru99 ---
[INFO] Deleting D:\SeleniumProjects\Guru99Project\Guru99\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # Guru99 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\SeleniumProjects\Guru99Project\Guru99\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # Guru99 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to D:\SeleniumProjects\Guru99Project\Guru99\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # Guru99 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\SeleniumProjects\Guru99Project\Guru99\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # Guru99 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.4.3:test (default-test) # Guru99 ---
[INFO] No tests to run.
[JENKINS] Recording test results
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # Guru99 ---
[INFO] Building jar: D:\SeleniumProjects\Guru99Project\Guru99\target\Guru99-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # Guru99 ---
[INFO] Installing D:\SeleniumProjects\Guru99Project\Guru99\target\Guru99-0.0.1-SNAPSHOT.jar to C:\Users\manchukondaanil_k\.m2\repository\Guru99\Guru99\0.0.1-SNAPSHOT\Guru99-0.0.1-SNAPSHOT.jar
[INFO] Installing D:\SeleniumProjects\Guru99Project\Guru99\pom.xml to C:\Users\manchukondaanil_k\.m2\repository\Guru99\Guru99\0.0.1-SNAPSHOT\Guru99-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.957 s
[INFO] Finished at: 2018-03-28T15:54:07+05:30
[INFO] Final Memory: 24M/181M
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving D:\SeleniumProjects\Guru99Project\Guru99\pom.xml to Guru99/Guru99/0.0.1-SNAPSHOT/Guru99-0.0.1-SNAPSHOT.pom
[JENKINS] Archiving D:\SeleniumProjects\Guru99Project\Guru99\target\Guru99-0.0.1-SNAPSHOT.jar to Guru99/Guru99/0.0.1-SNAPSHOT/Guru99-0.0.1-SNAPSHOT.jar
channel stopped
Finished: SUCCESS
You need to specify your testng.xml in your surefire section of pom.xml, that this is the testng suite that needs to be trigerred. Just making the testng.xml doesn't help. If you do not want the xml to be used then you need to do what #khmarbaise is pointing to - naming convention of file matters.

Can't get 'mvn test' run the tests

For some reason I don't know, sometimes, when I create a new Test project (I use IntelliJ + Maven module), I use the same pom file with some plugins which currently works in another projects, but then when I run the command line
mvn test
it doesn't run the JUnit test methods I have written. And I don't know what's wrong, it says:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building n26 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # n26 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # n26 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # n26 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\Automation\NewHomePage\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # n26 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\Automation\NewHomePage\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # n26 ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.713 s
[INFO] Finished at: 2015-09-24T13:02:50+02:00
[INFO] Final Memory: 19M/306M
[INFO] ------------------------------------------------------------------------
Normally, it will execute tests afterwards, but sometimes it stops here.
#wemu thanks, I named my file was xxxTests.java, and the naming convention is xxxTest.java. It works, thanks

How can I disable default lifecycle phases in Maven 3?

By disable I mean completely, entirely cut the phase from the lifecycle, so that it is not even invoked.
I might need a custom lifecycle but I could not find an easy way to define it straight in my pom.xml. It appears I need to write a plugin just to list phases I want.
For example, I would like default-testResources, default-testCompile and default-test phases to never happen and turn my build log from this:
[INFO] ------------------------------------------------------------------------
[INFO] Building HelpDesk Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # helpdesk ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory d:\proj\HelpDesk\repo\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) # helpdesk ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # helpdesk ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) # helpdesk ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) # helpdesk ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-war-plugin:2.3:war (default-war) # helpdesk ---
[INFO] Packaging webapp
[INFO] Assembling webapp [helpdesk] in [d:\proj\HelpDesk\repo\target\helpdesk]
[INFO] Processing war project
[INFO] Copying webapp resources [d:\proj\HelpDesk\repo\src\main\webapp]
[INFO] Webapp assembled in [40 msecs]
[INFO] Building war: d:\proj\HelpDesk\repo\target\helpdesk.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
into this:
[INFO] ------------------------------------------------------------------------
[INFO] Building HelpDesk Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # helpdesk ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory d:\proj\HelpDesk\repo\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) # helpdesk ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-war-plugin:2.3:war (default-war) # helpdesk ---
[INFO] Packaging webapp
[INFO] Assembling webapp [helpdesk] in [d:\proj\HelpDesk\repo\target\helpdesk]
[INFO] Processing war project
[INFO] Copying webapp resources [d:\proj\HelpDesk\repo\src\main\webapp]
[INFO] Webapp assembled in [40 msecs]
[INFO] Building war: d:\proj\HelpDesk\repo\target\helpdesk.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
If you want to continue using a predefined packaging (jar, war, etc.) you cannot totally remove them. You may leave the packaging as pom and define your own lifecycle by binding the goals you want to the desired phases, or you may define your own lifecycle entirely. You may also bind a default goal to phase none to prevent the goal from doing any real work as shown.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>default-testResources</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
All that said - khmarbaise's question is a good one. Generally it's not a best practice to change the existing pre-built lifecycles.

Resources