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.
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 have a maven module containing code but no tests. Tests are in another module.
code-module
test-module
I use JaCoCo to report about the code coverage, but it seems that no JaCoCo report is generated in the code-module because there are no tests to run. Without such report, the aggregate report in the test-module does not include the code coverage from the code-module's code.
How do I make sure the jacoco report is generated even when there are no tests?
Where I think the problem lies
I found out that the problem may lie with the way the maven-surefire-plugin handles the case where no tests are found.
The maven logs then show:
[INFO] --- maven-surefire-plugin:3.0.0-M6:test (default-test) # code-module ---
followed by
[INFO] --- jacoco-maven-plugin:0.8.8:report (report) # data-product-model ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
Adding a single test class (that may be empty) changes this output to
[INFO] --- maven-surefire-plugin:3.0.0-M6:test (default-test) # code-module ---
[INFO] Using auto detected provider org.apache.maven.surefire.junit.JUnit3Provider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.code.CodeCoverageTest
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.005 s - in com.example.code.CodeCoverageTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
and suddenly it generates surefire-reports/ and the jacoco.exec and site/jacoco/
(even though there are no actual tests, just an empty CodeCoverageTest.java),
so I see that the jacoco-maven-plugin is able to report:
[INFO] --- jacoco-maven-plugin:0.8.8:report (report) # code-module ---
[INFO] Loading execution data file /workspaces/example/code-module/target/jacoco.exec
Question
Instead of adding such a dummy test class, is there a way to configure maven-surefire-plugin to generate the jacoco stuff always?
Maybe something I can put in the parent pom, so it will automatically work for all child-module without tests.
[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.
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
I have a project for running tests. It's a maven project which uses Selenium. It runs correctly when launched locally, but from the Hudson platform, it throws NoClassDefFoundError:
Parsing POMs
[elsevier-selenium] $ "C:\Program Files\Java\jdk1.7.0_25/bin/java" -Xmx1024m -cp E:\hudson\plugins\maven-plugin\WEB-INF\lib\maven-agent-1.353.jar;E:\maven\boot\classworlds-1.1.jar hudson.maven.agent.Main E:\maven E:\hudson\war\WEB-INF\lib\remoting-1.353.jar E:\hudson\plugins\maven-plugin\WEB-INF\lib\maven-interceptor-1.353.jar 1753 E:\hudson\plugins\maven-plugin\WEB-INF\lib\maven2.1-interceptor-1.2.jar
<===[HUDSON REMOTING CAPACITY]===>channel started
Executing Maven: -B -f E:\hudson\jobs\tests-selenium\workspace\elsevier-selenium\pom.xml integration-test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building selenium-elsevier
[INFO] task-segment: [integration-test]
[INFO] ------------------------------------------------------------------------
[INFO] [compiler:testCompile {execution: default}]
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 5 source files to E:\hudson\jobs\tests-selenium\workspace\elsevier-selenium\target\test-classes
[INFO] [site:attach-descriptor {execution: default-attach-descriptor}]
[INFO] [failsafe:integration-test {execution: default}]
[INFO] Failsafe report directory: E:\hudson\jobs\tests-selenium\workspace\elsevier-selenium\target\failsafe-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running fr.elsevier.tests.disponibilite.SearchTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.203 sec <<< FAILURE!
fr.elsevier.tests.disponibilite.SearchTest Time elapsed: 0.203 sec <<< ERROR!
java.lang.NoClassDefFoundError: Could not initialize class fr.elsevier.tests.BaseSelenium
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at org.apache.maven.surefire.report.SmartStackTraceParser.getClass(SmartStackTraceParser.java:63)
at org.apache.maven.surefire.report.SmartStackTraceParser.<init>(SmartStackTraceParser.java:53)
at org.apache.maven.surefire.common.junit4.JUnit4StackTraceWriter.smartTrimmedStackTrace(JUnit4StackTraceWriter.java:72)
[...]
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
SearchTest extends BaseSelenium.
Which means it cannot even find a class in my source folder. The project structure is like this:
src/
fr.elsevier.tests/
disponibilite/
SearchTest.java
BaseSelenium.java
pom.xml
Why does the build generates these NoClassDefFoundErrors and how to fix it?
Try using -e or -X command line argument in local and hudson build. Then try to compare the classpath of the java processes launched.
You can then actually figure out which part of maven lifecycle threw the exception with better stacktrace.