I am tryinf a apporach to run a single test method from commandline using maven or either Junit. My project is build in Junit Framework with Maven.
I have parallel execution in place to run methods in parallel. When I try to run this from commandline, it is still running all testmenthds in parallel.
mvn -Dtest=<Classname>#<testmethodname> test
Would anyone help, how to acheive to run single testmethod or sepcific test methods from commandline.
Versions:
junit - 4.9
maven-compiler-plugin - 2.5.1
maven-surefire-plugin - 2.8
this is log for refrence
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building <ProjectName> 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) # ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) # ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.8:test (default-test) # ---
[INFO] Surefire report directory: C:\Automation\......\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Concurrency config is parallel='methods', perCoreThreadCount=false, threadCount=6, useUnlimitedThreads=false
Destroying 1 processes
Destroying process..
Destroyed 1 processes
Terminate batch job (Y/N)?
Spelling mistake spotted buddy, correct one is -Dtest and not -DTest
mvn -Dtest=<Classname>#<testmethodname> test
Additionally, as you are already running multiple tests in parallel, you can also use below mentioned pattern to execute like test methods.
Example:
mvn -Dtest=Classname#testMethod1+testMethod2+testMethod3 test
Enjoy... ;)
The surefire parameter for excuting a single test is test not Test so you should invoke the following Maven command:
mvn -Dtest=<ClassName>#<TestMethodName> test
For example, given ...
A test FooTest with a test method: foo()
A test BarTest with a test method: bar()
... you could invoke the following:
Run FooTest.foo()
mvn -Dtest=FooTest#foo test
Run FooTest.foo() and BarTest.bar()
mvn -Dtest=FooTest#foo,FooTest#bar test
Related
I configure my job as freestyle. And I need to run cases to a specified machine. MY project is maven project. I want to copy reports to master node after cases finish to run.
Jenkins ver. 1.483
I use pscp to copy files which works fine by hand in windows command prompt.
My command looks like:
mvn clean install -U
pscp -P 22 -i pgrsa.ppk -r %SLAVE_JENKINS_HOME%\workspace\%JOB_NAME%\target\surefire-reports ci#master:%JENKINS_HOME%/workspace/%JOB_NAME%
The pscp seems not work. When I use command like this:
echo EchoCommand is working.===
mvn clean install -U
echo EchoCommand is working again.===
EchoCommand is working again.===Not show at the output of the console while EchoCommand is working.=== has been shown. Why? Anyone knows that?
EDIT
C:\Tools\Jenkins\workspace\myproject-testng-sample-windows>echo EchoCommand is working.===
EchoCommand is working.===
C:\Tools\Jenkins\workspace\myproject-testng-sample-windows>mvn clean install -U
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.pak.automation:myproject-testng-sample:jar:1.0.0-SNPASHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-deploy-plugin is missing. # com.pak:pak-parent:2.0.0, C:\Users\pak\.m2\repository\com\pak\pak-parent\2.0.0\pak-parent-2.0.0.pom, line 484, column 12
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-source-plugin is missing. # com.pak:pak-parent:2.0.0, C:\Users\pak\.m2\repository\com\pak\pak-parent\2.0.0\pak-parent-2.0.0.pom, line 472, column 12
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building myproject-testng-sample 1.0.0-SNPASHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://mvn.pak.com/pakrepo/org/apache/maven/plugins/maven-source-plugin/maven-metadata.xml
Downloading: http://mvn.pak.com/pak-releases/org/apache/maven/plugins/maven-source-plugin/maven-metadata.xml
Downloading: http://mvn.pak.com/pak-snapshots/org/apache/maven/plugins/maven-source-plugin/maven-metadata.xml
Downloading: http://mvn.pak.com/third-party/org/apache/maven/plugins/maven-source-plugin/maven-metadata.xml
377/377 B
377/377 B 377/377 B
Downloaded: http://mvn.pak.com/third-party/org/apache/maven/plugins/maven-source-plugin/maven-metadata.xml (377 B at 1.5 KB/sec)
Downloaded: http://mvn.pak.com/pakrepo/org/apache/maven/plugins/maven-source-plugin/maven-metadata.xml (377 B at 1.4 KB/sec)
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # myproject-testng-sample ---
[INFO] Deleting C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\target
[INFO]
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) # myproject-testng-sample ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.0.2:compile (default-compile) # myproject-testng-sample ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.3:testResources (default-testResources) # myproject-testng-sample ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.0.2:testCompile (default-testCompile) # myproject-testng-sample ---
[INFO] Compiling 4 source files to C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # myproject-testng-sample ---
[INFO] Surefire report directory: C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator#4d20a47e
testMethod1
testMethod2
testMethodmyproject2
testmyprojectSample
testMethod1
testMethod2
testMethodmyproject2
testmyprojectSample
we wont run test with class name: com.pak.myproject.sample.NoInjectionTest
we wont run test with class name: com.pak.myproject.sample.NoInjectionTest
I am test method 2
parameter in test method is: firstname
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.895 sec
Results :
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # myproject-testng-sample ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\target\myproject-testng-sample-1.0.0-SNPASHOT.jar
[INFO]
[INFO] >>> maven-source-plugin:2.1.1:jar (attach-sources) # myproject-testng-sample >>>
[INFO]
[INFO] <<< maven-source-plugin:2.1.1:jar (attach-sources) # myproject-testng-sample <<<
[INFO]
[INFO] --- maven-source-plugin:2.1.1:jar (attach-sources) # myproject-testng-sample ---
[INFO] No sources in project. Archive not created.
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # myproject-testng-sample ---
[INFO] Installing C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\target\myproject-testng-sample-1.0.0-SNPASHOT.jar to C:\Users\pak\.m2\repository\com\pak\automation\myproject-testng-sample\1.0.0-SNPASHOT\myproject-testng-sample-1.0.0-SNPASHOT.jar
[INFO] Installing C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\pom.xml to C:\Users\pak\.m2\repository\com\pak\automation\myproject-testng-sample\1.0.0-SNPASHOT\myproject-testng-sample-1.0.0-SNPASHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.649 s
[INFO] Finished at: 2014-04-08T13:19:58+08:00
[INFO] Final Memory: 10M/24M
[INFO] ------------------------------------------------------------------------
Recording test results
TestNG Reports Processing: START
mvn is a batch file. So It is need to call mvn .... Not just mvn ....
See call-batch-file-from-cygwin-breaks-after-1st-command
This could be due to an environment problem. You could, however, save yourself a lot of time and work by doing things a little bit different:
Make your job a Maven Project, makes configuration easier (and offers you nice features like test reports for single modules etc.). This might also make your report copying unneccessary.
Depending on what you want to do with these reports afterwards, you could simple use the Jenkins archiving mechanism to copy them over to your master.
if you REALLY need to copy them by hand, use the Publish Over SSH Jenkinsn plugin
Are you using Execute Shell in your free-style project, i.e. you are running on a *nix based environment? If so, your problem is detailed in my answer here:
Jenkins Build Script exits after Google Test execution
Jenkins launches Execute Shell as a temporary shell script with command /bin/sh -xe tempshell.sh. Note the -e part. This tells sh to exit when any single command in the script returns with non-zero value.
Your mvn clean install -U is probably returning with a non-zero value. You can check that by running it on command line, immediately followed by echo $?
Solution: To circumvent that, add set +e to the top of your Execute Shell script.
The problem may be that you are not giving enter after the last command.
Today I came across the same problem in our project, last command in jenkins is not executed.
After some trail and error methods, came to understand that.
I am working on selenium and have created a maven project with user creation and user registration in Eclipse. There is no TESTNG involved in this implementation.
Now, I have created a maven job in Jenkins and configured the pom.xml path and goal set as 'clean install'.
While running this maven job from Jenkins, the build is success but none of the scripts from Eclipse ran for user creation and user registration.
I am seeing the below in the console output in Jenkins against the Job:
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # GDPortalDemo ---
[INFO] Surefire report directory: C:\RSV\Selenium\GDPortalDemo\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[JENKINS] Recording test results
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # GDPortalDemo---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: C:\RSV\Selenium\GDPortalDemo\target\GDPortalDemo-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # GDPortalDemo---
[INFO] Installing C:\RSV\Selenium\GDPortalDemo\target\HybridSauceDemo-0.0.1-SNAPSHOT.jar to C:\Users\daisy\.m2\repository\GDPortalDemo\GDPortalDemo\0.0.1-SNAPSHOT\GDPortalDemo-0.0.1-SNAPSHOT.jar
[INFO] Installing C:\RSV\Selenium\GDPortalDemo\pom.xml to C:\Users\daisy\.m2\repository\GDPortalDemo\GDPortalDemo\0.0.1-SNAPSHOT\GDPortalDemo-0.0.1-SNAPSHOT.pom
Earlier, I had sure-fire plugin in my pom.xml. I have removed that plugin from pom.xml now and then executed the job.
Can we run a maven job from Jenkins that doesn't have testng tests? In my project, we are not going to use testng. Appreciate any help on this please.
I have a fairly large maven project that if compiled (using mvn package or mvn install), stuck on a packaging stage for 10+ hours:
[INFO] Building jar: /home/peng/git-dev/scala-2.11/datapassports/spookystuff/mldsl/target/spookystuff-mldsl-0.6.2-SNAPSHOT-javadoc.jar
[INFO]
[INFO] --- maven-source-plugin:3.1.0:jar-no-fork (attach-sources) # spookystuff-mldsl ---
[INFO] Building jar: /home/peng/git-dev/scala-2.11/datapassports/spookystuff/mldsl/target/spookystuff-mldsl-0.6.2-SNAPSHOT-sources.jar
[INFO]
[INFO] --- maven-source-plugin:3.1.0:test-jar-no-fork (attach-sources) # spookystuff-mldsl ---
[INFO] Building jar: /home/peng/git-dev/scala-2.11/datapassports/spookystuff/mldsl/target/spookystuff-mldsl-0.6.2-SNAPSHOT-test-sources.jar
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:test-jar (default) # spookystuff-mldsl ---
[INFO] Building jar: /home/peng/git-dev/scala-2.11/datapassports/spookystuff/mldsl/target/spookystuff-mldsl-0.6.2-SNAPSHOT-tests.jar
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) # spookystuff-mldsl ---
[INFO] Installing /home/peng/git-dev/scala-2.11/datapassports/spookystuff/mldsl/target/spookystuff-mldsl-0.6.2-SNAPSHOT.jar to /home/peng/.m2/repository/com/tribbloids/spookystuff/spookystuff-mldsl/0.6.2-SNAPSHOT/spookystuff-mldsl-0.6.2-SNAPSHOT.jar
[INFO] Installing /home/peng/git-dev/scala-2.11/datapassports/spookystuff/mldsl/.flattened-pom.xml to /home/peng/.m2/repository/com/tribbloids/spookystuff/spookystuff-mldsl/0.6.2-SNAPSHOT/spookystuff-mldsl-0.6.2-SNAPSHOT.pom
[INFO] Installing /home/peng/git-dev/scala-2.11/datapassports/spookystuff/mldsl/target/spookystuff-mldsl-0.6.2-SNAPSHOT-javadoc.jar to /home/peng/.m2/repository/com/tribbloids/spookystuff/spookystuff-mldsl/0.6.2-SNAPSHOT/spookystuff-mldsl-0.6.2-SNAPSHOT-javadoc.jar
[INFO] Installing /home/peng/git-dev/scala-2.11/datapassports/spookystuff/mldsl/target/spookystuff-mldsl-0.6.2-SNAPSHOT-sources.jar to /home/peng/.m2/repository/com/tribbloids/spookystuff/spookystuff-mldsl/0.6.2-SNAPSHOT/spookystuff-mldsl-0.6.2-SNAPSHOT-sources.jar
[INFO] Installing /home/peng/git-dev/scala-2.11/datapassports/spookystuff/mldsl/target/spookystuff-mldsl-0.6.2-SNAPSHOT-test-sources.jar to /home/peng/.m2/repository/com/tribbloids/spookystuff/spookystuff-mldsl/0.6.2-SNAPSHOT/spookystuff-mldsl-0.6.2-SNAPSHOT-test-sources.jar
[INFO] Installing /home/peng/git-dev/scala-2.11/datapassports/spookystuff/mldsl/target/spookystuff-mldsl-0.6.2-SNAPSHOT-tests.jar to /home/peng/.m2/repository/com/tribbloids/spookystuff/spookystuff-mldsl/0.6.2-SNAPSHOT/spookystuff-mldsl-0.6.2-SNAPSHOT-tests.jar
(this is the last line of output)
The build output can be observed on CI server, with similar output:
https://app.codeship.com/projects/166836/builds/48698210?pipeline=103aace8-047a-47e4-9cb9-018c3ce0693a
I don't know what have caused this behaviour, but I suspect that a bug in maven-shade-plugin has caused dependency reduced pom generation to move into a indefinitely loop. How can I confirm this hypothesis collect enough evidence to report to the plugin maintainers?
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
[Update: Problem cause found! read below]
Problem: VSTS Maven build does not seem to run JUnit, does not show any JUnit results, does not seem to produce any JUnit testreports.
In VSTS, we have a Java project with a Contact and TestContact class with 1 testcase;
source\module\src\main\java\nl\customer\model\situation\Contact.java
source\module\src\test\java\nl\customer\model\ContactTest.java
source\module\pom.xml
Running Maven from Eclipse works fine. Console shows Maven using Surefire reports, running/passing the 1 unit test.
Running the project with Maven on a Windows PC also works:
mvn test
Logging:
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Domain Model
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # module ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 30 resources
[INFO] skip non existing resourceDirectory C:\project\source\projectdomain\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # module ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # module ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\project\source\module\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # module ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.20.1:test (default-test) # module ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running nl.customer.module.ContactTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 s - in nl.customer.module.ContactTest
[INFO]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.109 s
[INFO] Finished at: 2018-01-09T14:05:03+01:00
[INFO] Final Memory: 10M/196M
[INFO] ------------------------------------------------------------------------
In VSTS, using the Maven build step (goal: install) succeeds, but the log does not show anything about JUnit, even with system.debug = true.
Consequently, trying the "Publish test results" always fails (both when using a seperate build task or the Publish TFS option in the maven build task).
It seems I have found the cause of the problem: in VSTS, the Maven build task has the option
Set MAVEN_OPTS to
In our build definition, this was set to
-Xmx1024m -X
The first parameter is correct, it sets the maximum memory.
The second parameter is incorrect. If you want Maven to give debug output, you should put the "-X" parameter under Goal(s).
There is no real warning about the second parameter in the logging.