I have a question regarding test automation with Apache Maven.
Is it possible to configure Apache Maven to run Unit Tests, then package the Java Project as an OSGI Bundle, deploy it to a Karaf OSGI Container and finally run SOAP UI Tests on it (Cleaning the bundle from the Container is not that important but if someone knows how to do this aswell, I'd be happy to hear about this ;) ).
I know that unit testing, packaging and SOAP UI testing itself is not the problem. But how do I get Maven to execute the steps in the order as described (and especially how can I tell Maven to deploy a bundle to an OSGI Container)?
Greetings,
Pascal
This sound more like an integration test.
If you instrument the OSGI deployment and the running of SoapUI tests via java code, then from the maven perspective it is very simple.
Is this a workable solution for you?
Just set up integration tests via a maven profile and run tests as normal: mvn clean test -Pintegrationtests
Related
Currently I work on a java web application that is build with maven 3. The integration tests for the application are written in ruby using minitest and capybara. Currently I use c-ruby and bundler to run the tests. For Jenkins integration we use the ci_reporter gem and a rake task.
I want to integrate the testing with the maven lifecycle. For this I use the cargo-maven2-plugin to start and stop an application server in the pre-integration-test and post-integration-test phase. What i am trying to achieve is to run the ruby integration tests in the integration-test phase.
What is the best way to add dependencies? Is it possible to use bundler?
How to start the tests using jruby?
How can I package JUnit tests in OSGI bundle so that to run them with Apache Felix? Is there a standard implementation or some work around as to create separate bundle for JUnit tests and run them in activate method?
Edit: I've forgot to say that the project is created with Maven.
Update: Thank you for your answers. I've used junit4osgi framework and it's very useful.
If it's for running unit tests you may want to have a look at Pax Exam.
You might want to take a look at how BndTools does this. It allows you to create integration OSGi tests which can be executed in an OSGi container.
The Apache Sling testing tools' org.apache.sling.junit.core bundle lets you run JUnit tests in an OSGi instance. It's part of the Sling project as it was created there, but should run on any OSGi environment without any Sling dependencies.
I can't find an easy JSFUnit setup for my pom anywhere. What repository do I use and which dependencies? We have a running web app with JSF and Spring. Can't be that hard to get JSFUnit into the mix..?!
Also we want to run the tests from Eclipse (I think I found something there) and via Maven when building the artifacts on jenkins.
Can anyone please post their dependency setup (as well as maven build cycle integration)?
Thanks!
The followings are ok now:
I have a multi-module project in maven with EJB and WAR projects
I want to use JMeter (and later selenium) for integration testing. I can run both from Maven. The JMeter plan is ready, I run it with Chronos maven plugin.
My application is a Java EE application, so I want to test the code with the planned production aplication server, which is Glassfish 2.11. I can create/start/deploy/stop and anything like that with glassfish maven plugin
I have put jmeter and glassfish related build settings into a submodule in maven, which is dependent on all of the other modules, so in build lifecycle it is the least, and for this reason a good point to test the whole application
My problem is, that how can I reach the followings:
deploy NOT instrumented code, but run integration tests on instrumented one
how to get coverage info from application server
I wanted to use emma4it which was created to instrument artifacts. It would be good for me, but i cannot make it instrument the war file in the other submodule. I do not even know anything about the supported arguments of emma4it, since I did not find it at all (just a binary in repository), no documentation and no source (I know I can decompile it)
I want to have a coverage raport at least in maven site, but the top would be to have it in Sonar
Could you give me advice, how to do this? I can provide POM snippets if you need it.
FINALLY. The solution arrived. See at http://www.sonarsource.org/measure-code-coverage-by-integration-tests-with-sonar/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+Sonar+(Sonar)&utm_content=Google+Reader
I currently try to do it.
Let me explain some of my constraints.
We have a war that has a CXF Soap service and a Spring MVC REST Service. Both the CXF and Spring MVC implementations are in a separate jar and are brought in as dependencies. The REST service has its unit tests in its project.
I was wondering if there was any way to, while doing something like 'mvn clean test' in the REST jar, to have a local version of the war set up and then run the unit tests. Thus, when building in something like Hudson or doing releases, there won't have to be any workarounds (such as deploying a snapshot ear or running a local war manually)? I've seen this done when the tests are within the war using cargo, but not when the tests are separate from the war.
Right now, we're going to take the tests out into a separate jar but that's still not ideal as if something happens to go wrong during a release, that'd mean the REST jar and war were already released. I'd prefer do it the above way, with the tests in the same project as the REST service.
If anyone has any pointers or doc or examples that could help with this, it would be appreciated.
Honestly, I'm not sure I understood all the constraints. Anyway, the recommended way to implement integration tests with Maven is to put them in a separate module (that's much easier, especially if the module under test also have unit tests) that depends on the war/ear under test and to:
Start a container and deploy the war/ear during the pre-integration-test phase
Have Maven run the tests during integration-test
Stop the container during post-integration-test
For the steps #1 and #3, I personally use Cargo. For the step #2, using the Maven Failsafe Plugin is the preferred option (because it won't stop the build if a test fail). At least, this is what I use and I have used the resources below to build my setup.
An alternative approach would be to start/stop an embedded container from the tests. For example, this is doable with Jetty, see Embedding Jetty and Unit Test Servlets with Jetty.
Resources
Functional testing with Maven, Cargo and Selenium
Maven and Integration Testing
Maven and Selenium
Unit Test Servlets with Jetty
Maven has also integration-test phase. Use maven-jetty-plugin to start container and deploy application. Then run your integration test.
Maven Jetty Plugin
Maven and Integration Testing
Update
Tests cannot be in a jar file. Maven surefire plugin could not run them. The tests are part of the project where you run integration test. The tested war file can be set as dependency library. It will be downloaded, deployed and the you run integration tests.