How to have a proper JMeter Maven Tomcat workflow? - eclipse

I have, a few JMeter scripts, which make HTTP calls to test my own web service, written in Spring. I would like the JMeter scripts to be automatically executed for every build and test if the build is good. So, as suggested at:- http://ribblescode.wordpress.com/2012/04/16/how-to-run-jmeter-tests-with-maven/ I have set up my Maven .pom files of my Spring web service project to have the Jmeter plugin stuff defined. And, I have added my JMeter scripts to src/test/JMeter. Now, I use Eclipse as my IDE and when I have my project already running on Tomcat from within Eclipse (Run As-> Run on Server) and then do Run As->Maven Install on my project with this setup, it executes the JMeter scripts and works as intended.
However, if my web service is not already running on Tomcat, the Maven build fails as the JMeter is not able to successfully make the HTTP calls.
Now, my problem is that this setup means the JMeter script is actually making calls to the old build which is already running and not on the new build which was generated when I clicked on Run As-> Maven Install at that point in time.
So, given this scenario how do I have it so that, when I make some code change, and then do a new build using Maven, it first deploys it and then runs the JMeter script on this new build?

Maven is not intended to test the Tomcat running in your Eclipse. Jmeter is an integration test tool, so all you have to do is to haang the appropriate plugins on the appropriate maven lifecycle phases. You actions needed:
pre-integration-test phase steps
download and unzip Tomcat
deploy your packaged webapp
start tomcat
integration-test phase step
Download and unzip Jmeter (for example with maven-dependency-plugin)
run jmeter tests
post-integration-test phase
stop tomcat
Thats all you need. One tool to use could be the Cargo Maven Plugin, which helps you in deployment, start and stop.
An example is here http://www.alexecollins.com/content/jmeter-integration-test-template-pom/
If you are interested, it is also possible to collect coverage info for your JMeter tests: http://docs.codehaus.org/display/SONAR/Code+Coverage+by+Integration+Tests+for+Java+Project

Related

Running tomcat by adding external server vs inbuilt maven

I want to know the difference in running an application in eclipse by both ways below:
1)Run the application as maven build with 'tomcat' dependency in the pom.xml
2)download tomcat from apache site and add the server, run the tomcat and then run the application as server.
Lets say, my project name is 'messenger'. When I did using first step, i can access with below link"
http://localhost:8080/
but when i did as second step, i can access using below link:
http://localhost:8080/messenger/
can someone, please explain why the difference? arent both the same?

Headless eclipse managed by Jenkins to run OSGi application server

we would like to adapt our Jenkins CI roundtrip as it takes to long (late feedback).
The current flow looks like described below:
OSGi server bundles are checked out and build with ant.
the OSGi bundles are packaged to be used on linux distros.
a server is set up to install the above packages and to run HTTP interface tests (integration tests) against it.
We would like to get rid of creating the linux packages and to install a server with these packages as this consumes most of the time.
Instead we would like to execute the existing tests against a headless eclipse which is running the server (based on compiled jars or imported projects if possible) managed by Jenkins CI.
Now some questions:
Is it possible to run a headless eclipse within Jenkins (I think so as it is just executing a java application)?
Is it possible (and does it makes sense) to have an eclipse instance permanently running and to get used from more than one job? So we have to only update the jars/imported projects that have been changed ... or
do we have to extract eclipse and set it up each test run?
Is it possible to import projects within the headless eclipse or do we have to throw compiled jars into its installation?
Are there any other ways to get HTTP interface tests executed against a running server we are currently not thinking about?
Thanks a lot!

Automate JUnit tests for functionality on the server in Eclipse?

I would have added some JUnit tests to an Eclipse project that test functionality on the server to an Eclipse web project.
I can run the web application from inside Eclipse on an external Tomcat server (Run As | Run on Server) and then run the JUnit tests also from inside Eclipse while the first is still up.
I understand that is should be possible to fully automate both steps as one by making use of a Jetty (instead of Tomcat) server that runs inside Eclipse and that could be booted e.g. in #BeforeClass (or earlier).
Does Eclipse support this kind of unit testing out-of-the-box. I am currently using Eclipse Java EE IDE for Web Developers (Version: Kepler Service Release 2).
Eclipse (and any other IDE for that matter) doesn't stop you from doing anything in unit tests. It doesn't really support much, either, which is the core of your problem: Eclipse won't start a server for your unit tests. The same is true for all other IDEs that I know of.
Instead, you need to read up on how to embed Jetty in a Java application (= your unit tests) so the first test can start the server. Use a lazy init pattern for this:
private static JettyManager jetty;
#Before public void startServer() {
if( null == jetty ) {
jetty = new JettyManager();
jetty.start();
}
}
You can use a JVM shutdown hook to cleanly stop the server.
I use the same pattern to create the database which should be used during the tests to make sure it's clean. For this, I embed an H2 database.
If you want more automation, look at Maven. It can run integration tests (including deploying the WAR before starting the tests). See http://www.benoitschweblin.com/2013/03/run-jetty-in-maven-life-cycle.html
With the Maven Cargo plugin, you can deploy to almost every J2EE container.
Or use Jenkins: http://programmaticponderings.wordpress.com/2013/11/13/building-a-deployment-pipeline-using-git-maven-jenkins-and-glassfish-part-2-of-2/

Running selenium test suites with Maven/Eclipse for dummies

I have to test a web app using Selenium test cases/test suites that will run through Maven. I am new to it all. Can anyone outline the simple basic steps to run my first test successfully? I have everything installed (Eclipse, Maven, Selenium). Thanks.
Might help to see an active example and working integration between jUnit, eclipse, Maven and Selenium.
You can download a working project here
or you can check it out from GitHub from here.
If you read the readme on that project, it states that you can run the tests individually by right clicking the method names, and clicking Run As->jUnit tests or you can run the class suite.

How to force eclipse to republish project when changing source in another module

I have multi module maven project.
One of the modules is actual web application, the JBoss is the server.
Other subprojects are dependencies for the web project.
I am running it in JBoss embedded in eclipse. Pretty straightforward configuration.
When executed from within eclipse, if I do mvn clean, mvn package - then clean + publish to JBoss, everything works wonderfully.
If I change source code for the web project, eclipse detects the need to republish automatically and does job well.
However if I change source in the non-web subproject, eclipse does not detect change and I have to mvn clean, mvn package, then publish to JBoss manually for it to pick the code change.
This is annoying since packaging job takes about a minute, then publishing job takes another 30 seconds. I have to clean since simply packaging without clean does not pick the change either.
Is there a way to configure things in the eclipse so that any source change in any subproject/module is automatically recognized by eclipse and it would republish to JBoss upon selecting "run"?
There is another bad side effect - debugging of the source that is not web project is impossible - eclipse's debugger does not see that source. It sees only source of the web module.
Thanks,
Nikolay
Make sure that your web project has dependencies on the other modules(projects) defined in the pom and in the eclipse project. you can check that in the build settings. If they are not there then it probably means that the project file was not generated from your maven .pom file. You can generate that by running
mvn eclipse:eclipse