How would you run integration test separately after deploy is done.
In jenkins we will build, unit test, run some kind of embedded integration tests.
Then it will deploy to remote server.
How can I run Integration tests against remote deployed server? Running same fail-safe plugin will build the application again. The test will be rest-assured java based tests. How to invoke them without rebuilding the app?
Is the only way to somehow play with profiles? Profile for build and test and profile for black box integration(skiping unit tests and embedded integration test)
Maybe I can bind to maven validate phase, which will skip compilation with profile activating "black-box" fail-safe execution(for validation phase only)
Related
I found several post that explains how to run integration tests wising maven and docker. They basically explains hoy to use/setup fabric8 maven-docker-plugin and maven failsafe plugin.
I'm wondering if is possible to use fabric8, for example, with surefire. My specific need is: I need to run my tests (JUnit tests) but first I need/want to start a docker image with MySQL running on it.
I'm not tied to fabric8. If there is another way to start the docker image before start my tests and stop/kill it once tests run finish, that will help me a lot.
Thanks in advance.
Maxi
Yes you can definitely do that. The idea is to use a maven docker plugin such as fabric8 docker plugin and start a container before the test phases and stop it after the test phase.
But note that technically tests that connect to databases are not unit tests, they should be integration tests.
There are many tutorials online to do that such as INTEGRATION TESTING WITH DOCKER AND MAVEN
You can adapt this for unit tests by just changing the phases when the docker plugin runs.
You can change <phase>pre-integration-test</phase> to a phase that starts before the maven test phase such as <phase>generate-test-resources</phase> and stop the container once the test ends for example:
<phase>prepare-package</phase>.
Note that there are no nice phase names as there are for integration test, as it is not ideal to start external services when running unit tests. But anyway it works.
For a complete reference on maven phases check Introduction to the Build Lifecycle
using maven we create a war file and we need to be deployed this war in tomcat(application server) for different environment (DEV/QA/UAT).
We need to run the JUNIT test for each of the environment before deploying.
we have written nearly 60 junit test which need to passed
Is is possible to run the junit test for war file?
if yes how to run all junit test sitting inside the war file
WAR file is deployment artifact that shouldn't include any unit tests. As #Gerold Broser correctly pointed out, Maven handles excluding of unit tests for you if you place them into "src/test/java". Don't ever try to put them into "src/main/java".
we have written nearly 60 junit test which need to passed
Is is possible to run the junit test for war file?
If they are true unit tests, they don't need to be executed against deployed war service. They are testing small chunks of functionality and are generally executed during test phase of maven lifecycle.
If tests are firing requests against deployed server, at that stage they are not unit tests anymore and should be probably placed into separate test project.
Proper place where to run your tests is always Continuous Integration server, so one way or the other make sure that execution is automated! Tests without CI server are waste of time.
BTW
There is maven-tomcat7-plugin to start tomcat and deploy it during interation-test phase of Maven lifecycle, but this maven plugin doesn't seem to be maintained anymore and doesn't work with Servlet 3.0 Java configs and Tomcat 8. So I don't recommend that path.
My development environment is Netbeans 7.4 and Maven 3.0.5 (bundled with Netbeans). I'm using JUnit 4.11 to build unit (class names ending with Test) and integration tests (class names ending with IT). I'm running unit tests and excluding integration tests with the "-DskipITs" Maven option. I have a custom action which runs just the integration tests with the failsafe plugin. Both execute successfully. However, I only see the results in the "Test Results" window when running the unit tests. How can I get the integration tests to show in the "Test Results" window? With the integration tests, I'm only seeing the output in the console.
The maven-failsafe-plugin only executes in integration-test and verify (and of course the help) goal while the maven-surefire-plugin runs during test goal.
NetBeans Test Results window only shows the tests that were executed using the 'test' goal.
My solution for this situation is to categorize my integration tests into
testintegration - just lightweight ITs, I run them with surefire (to see them in Test Results window)
testheavy - those that will require me to bootstrap something I run with the fail-safe plugin
I hope you have the option of doing something close to that.
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?
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.