How do I call Junit test (Rest call) cases after deploy war in tomcat through Jenkins? - maven

I am doing continues deployment of my Project war through Maven(Build tool), jenkins(CD tool) and SVN as version control.
I am able deploy war to tomcat , now i want to run some junit which call's Rest web services to that deployed jar, how would jenkins do it ?

You can do this via "execute shell" in jenkins. Firstly, you can check whether "execute shell" is been installed in your jenkins or not it comes as a add-on. If you have shell, you can write a small piece of code to execute your code. Remember this code will be executed on the jenkins slave box which has used to deploy your war.
Start jar file : java -jar .jar
2 ways to do that :
A) mvn exec:exec -Dexec.args="arg1" (this needs maven to be installed on the jenkins box), call you test case directly. Remember before running you should be in directory path.
For example :
cd ${HOME}/(code directory which you want to navigate to in order to run command) - Here HOME is /home/jenkinsUser
Now you are the location(although the first step is optional, you can run without navigating to the location), from where you want to run your unit test case. You can run them as a java command from there, passing the parameter to the deployed jar.

Related

Run tests located within a fat maven jar?

I have a maven project which is a test harness including tests.
The tests can be run using surefire, within intelliJ. And the IDE states the command line it is running in order to do this:
java
-Dmaven.multiModuleProjectDirectory=...
"-Dmaven.home=...
"-Dclassworlds.conf=...
"-Dmaven.ext.class.path=...
"-javaagent:...
-Didea.version=...
install
If I put the jar on another machine, and wish to run the tests contained within it (ideally with surefire plugin) should I be aiming to construct a similar command line as to the above, or run something like mvn test {jar name} or mvn surefire:test {jar name}

How to redeploy WAR inside a JBoss WildFly container?

I am trying to make my local Java development environment more lighter.
Dockerfile multi-stage steps looks like this:
MAVEN CONTAINER
build app from source code
WILDFLY CONTAINER
prepare server (data sources, drivers)
copy WAR from MAVEN
start server and deploy application
This usually takes about 1-3 minutes, even with dependencies-offline-mode.
After making some code changes I have two options - build new image (1-3 minutes) or manually build WAR and redeploy app from WildFly Administration Panel. Is there any tool to automate this?
Maybe this basic approach will be enough:
0. start local env as always
1. make some code changes
2. build WAR in MAVEN conotainer
3. copy WAR into WILDFLY container
4. enter WILDFLY container bash and redeploy using JBOSS-CLI
Are you using some Maven plugins? Bash scripts? Thank you for hints!

How to test a web application with jUnit/selenium from Jenkins that is deployed outside maven (in this very Jenkins)

I have to test a webapp, that is build with maven from Jenkins as CI. The Jenkins instance deploys the webapp via script as 'post build step' to a test enviroment. After the deployment some integration tests should be fired and the results should go back to the jenkins instance.
I can't let maven itself deploy the webapp and utilize surefire/failsafe, because I am not allowed to do so.
I already have a little java app, that uses Selenium WebDriver to perform JUnit tests. I could run this app as 'post build step' like this:
java -cp /usr/share/java/junit.jar junit.textui.TestRunner [test class name]
but I have no ideas how to include dependecies (probably somehow like this: Selenium Scripts on the command line) and how to get the results back to Jenkins.

How to setup jenkins to run Selenium / Maven / TestNG

I'd like to be able to run by Jenkins a series of test from Selenium. I've see a lot of topic about the subject but it's not clear to me.
Do I need to call maven to run the project or can I directly call Testng ?
Also do I need with Jenkins to call my project using maven or using Ant ?
What is the best practice. Is there specific plugin that I need.
Do I need to call maven to run the project or can I directly call Testng ?
You can call testng through maven or ant. There is no direct runner plugin for Jenkins.
What is the best practice. Is there specific plugin that I need.
You might need the TestNG plugin to show the results inside Jenkins, but it is optional. Best practice is to use maven or ant. You can find a nice ant example here
You can use run TestNG scripts in Jenkins with or without Maven. Maven as a build tool, in my opinion, looks more robust and gives you more flexibility than Ant.
To run pure TestNg script in Jenkins, enter the following in the 'build' section:
D:>java -cp "Pathtolibfolder\lib\*;Pathtobinfolder\bin" org.testng.TestNG testng.xml
Click on Save button.
Note: The actual path of lib and bin folder need to add the in above
command.
After saving the command, Jenkins will build project in predefined
time, and this command will run using TestNG.
The result will be stored in custom report HTML file that can be sent via
email with a small Jenkins configuration

Jenkins Inegration with TestNG.(when running from jenkins it's not invoking browser)

My project contains (Webdriver,Maven3.05,jenkins) when I run maven command "mvn test" , test will trigger and browser will be invoked, the same set when i had configured using jenkins it will run the tests but browser will not be invoked.Please help me where iam going wrong.(I had installed testng plugin for jenkins all necessary configurations are taken care).
Try starting jenkins using the command line:
java -jar jenkins.war
Usually in Windows not all the services are allowed to use the interface
Hope helps!

Resources