I had been introduced to concept of CI lately and was trying to work on jenkins CI. I was stuck up in one thing . How to trigger executable testng files in jenkins CI. For ex locally in our machines we just run testng.xml to execute couple of test cases. In the same way how can we trigger this xml file to run in jenkins CI ?
In most cases with jenkins you wouldn't use an executable. Normally you'd run the wrapper for the tests (Junit/Nunit etc.) which Jenkins is fully capable of running on it's own.
You can use this article to run TestNG tests using Maven:
Running TestNG tests using maven
After configuration is completed just add Invoke top-level Maven targets step to the Build Steps in Jenkins (Maven plugin should be installed). The target should be test in this case.
If you will face with any errors during configuration, try to google them.
If you are not using any build tool like maven or ant, you can invoke it from command line as we'll and specify your suite file. Make sure to set the correct class paths http://testng.org/doc/documentation-main.html#running-testng
You can put this as a build step in Jenkins.
Add a compilation step prior to this step. I haven't ever tried it - have always used ant or maven, but that is where I would start exploring.
Related
I'm writing code in Intellij and have a JUnit test class included in a project and i understand that running of JUnit should always be done at build time.
Is there a way to first run the JUnit and only if there were no test error run the project itself ? I want them to run together with 1 click (NOT run them seperately/manually).
Also, i would like the above to work even when the project is packed as a .jar file.
How can it be done ?
Thanks !
In Intellij:
Run -> Edit Configurations
Create a JUnit configuration for your tests
Create a Run configuration for your project.
And on "Before Launch": Add -> Run Another Configuration and choose the one created at point 1.
It doesn't matter how your project is packed (jar, ...)
Normally this is done by using a build management tool like: maven, gradle, ant. In this way the build tool will run tests for you and stop if they fail.
With maven, it's just a command: mvn clean package exec:java which will compile code, build project, run tests and execute your code.
See example project: https://github.com/HaveACupOfJava/maven-jar-demo
I have inherited a codebase whereby we have a maven project of component tests that use junit as the framework that runs the tests.
Everything runs OK, but the problem is that these tests must be compiled into a jar-with-dependencies so that they can be run on a standalone computer with very limited outwards connectivity (e.g does not have access to maven central).
I have managed to create a runnable jar with dependencies which I can run using junit.jar and the command line like so:
java -cp jar-with-dependencies.jar:junit.jar junit.jar org.junit.runner.JUnitCore com.testsuite.AllTests
This works but the problem is that I also need to output the junit results into XML, like maven's surefire plugin does.
My question is, can I run this jar-with-dependencies using maven such that it creates the junit xml reports?
I can successfully run the tests using exec-maven-plugin which essentially runs the previously stated command
TFS and TestNG - Possible to Execute TestNG test(s) within TFS2015?
I have uploaded a Java Maven project to a Repo in my instance of TFS.
My java Maven project comprises of TestNG Test / classes
I can see that there is a Maven plugin within the TFS which also has a JUnit link.
4. I cant see any option to enable me to execute TestNG tests within the TFS, is it even possible?
It's able to use Maven task to build a Java application or test the application including TestNG test. Detail steps please refer this tutorial: Get started testing Java applications with Visual Studio Team Services
For test result report just follow juherr's reply in this question.
Yes you should be able to run your TestNG tests.
I think its eventually going to be Maven that is going to be executing your tests.
Maven makes use of surefire-plugin to basically execute your tests. For TestNG here's two of executing tests via surefire-plugin
If your test matches the default pattern "/Test*.java", "/*Test.java", "**/*TestCase.java" (See here)
Create a suite xml file for TestNG (See here) and have surefire plugin refer to it (see here).
After some research into running Cucumber on Jenkins I have come to a dead end, I have read some post here about Running Cucumber but most are error not the process.
Running via command line the problem here is that I don't know how to call this in Jenkins after building.
I have Jenkins running on an Ubuntu server. Everything for building a maven project is setup, but how would one run the Runcukes file or setup the pom file in a way to call cucumber to start running?
Wire up a Maven task to run cucumber. As cucumber generates stubs for junit, maven's surefire plugin will run the tests nicely.
Jenkins has full support for running maven builds, so you won't have any issues there.
Is there a way to read a build artifact file using the Groovy postbuild plugin?
Some context:
I have written some testng tests that are run by maven in Jenkins. Jenkins runs the tests, gives me the test results, etc. However, I have been asked to also store the results in HP's Application Lifeycycle Management (ALM). A coworker provided me with a post-build groovy script that can interface with ALM and store the test results. I have to pass these parameters to that script:
jobname
pass/fail status
test start time
My idea was to store testng-results.xml as an artifact and parse out the results with xmlslurper, but I don't know how to read the artifact from the groovy plugin. From the groovy postbuild plugin page I have gathered that it might also be possible to read the test results directly from the manager.build variable, but I don't have a lot of experience with Jenkins or this plugin and so far I have been unsuccessful.
I'm also open to other approaches as well. The groovy script is running on the Jenkins server, not on the slave node.
In case this is useful for anyone in the future, the solution that I went with was to find the artifact that I was looking for in manager.build.getArtifacts() and join that path with manager.build.getArtifactsDir()