cucumber tests on docker won't fire at the integration-test phase - java

I'm having some problems getting my cucumber/phantomJs test to run against the docker container.
My plan is to start the tomcat docker container at the maven pre-integration-test phase. Then at the integration-test phase i want to run the cucumber tests. For this i have disabled the surefire plugin to run test phase and included the failsafe plugin. Though some how the integration-test phase does nothing. I have no idea whats wrong with it.
The docker containers work fine and are started at the pre-integration-test phase. They also stop at the post-integration-test phase. The war is deployed and runs like it should run. No problems there.
The cucumber tests run at the test phase when the surefire plugin is enabled for test. In the sample project you can change this by editing the pom at the section for the surefire plugin with to
<configuration>
<skip>true</skip>
</configuration>
I have created a sample project at https://github.com/abroer/cucumber-integration-test.git
The project can be run using mvn clean verify
Any suggestions on how to fire the cucumber tests at maven integration-test phase are appriciated.

Your cucumber test runner is called RunCukesTest. This pattern is not included by default by the failsafe plugin, see https://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html#includes . You have either to rename your class to say RunCukesIt or adjust the configuration of the failsafe plugin.

Related

Jmeter maven plugin skip unit tests

I am trying to run jmeter tests with jmeter maven plugin as shown in https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/wiki/Configuring-the-jvm-that-the-jmeter-process-runs-in
When I run mvn verify it runs the jmeter test but also all the unit tests under src/test/. Is there a way that I can skip unit tests and only run the jmeter test?
Thanks in advance!
The easiest is just running single jmeter goal like:
mvn jmeter:jmeter
this way you will run only performance tests, all other build procedures will be skipped.
A harder but more flexible way would be using Maven Builde Profiles, see Maven – How to skip unit test
More information: How to Use the JMeter Maven Plugin

How to run maven test with mysql running in docker (using maven-surefire-plugin)

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

Executing a maven lifecycle target on artefact installed in local repo

Is it possible to execute a lifecycle target (e.g. integration-test) on an artefact that has been installed within the local repo?
My use case is as follows. I have a multi module project with many modules that dedicated various types of integration testing (compliance test, performance tests, etc). I need to invoke these integration multiple times with different environment configurations. These configurations are expressed as maven profiles and parameterised using properties. I want to avoid recompiling the project over and over again.
I would like to have one build CI job performing the mvn install, then separate CI jobs performing the integration tests, triggered once the build CI job has passed. The integration tests would simply invoke integration-test lifecycle phase of the installed artefact setting the profile and passing the parameters
I have tried pointing mvn at the .pom file within the local repo but this does not work. It fails because it cannot find classes within the artefact's own JAR file (as if it were not being put on the classpath) - a problem that doesn't occur if I have my integration job checkout the tree and invoke the pom.xml within the source tree.
mvn -f ~/.m2/repo/x/y/z/myproj-perftests-x.x.x-SNAPSHOT.pom integration-test -Pmyprofile -Dparam1=blah
No, it is not possible. Maven plugins (normally) only work with project sources.
If your only concern is recompiling project again and again, consider splitting your project into the core part and the integration tests part. Then when running integration tests you'll only need to recompile the integration tests part.

Maven: How to clean integration-test configurations

In our maven project, we have integration test that sets all sorts of things on the integration test server.
I want to be be able to easily clean this things in a command. I want to be able to run:
mvn integration-clean
And this will clean all the things on the server, by running some cleaning mojos from my maven plugin.
How should this be done?
These are the commands in order to perform a complete integration test:
Step 1: mvn deploy
Step 2: mvn integration-test
Finally do a complete clean install in order to update the changes.
Step 3: mvn clean install
You could refer this for the exact life cycle of the build.
You must be having the integration profile defined in settings.xml.
<settings>
...
<activeProfiles>
<activeProfile>integrationProfile</activeProfile>
</activeProfiles>
...
</settings>
Assuming the integration profile is active ,
mvn clean install -P integrationProfile
should work for you.

Maven Unit Tests

I am working on a project written using Maven.
If I do
mvn clean install
then I expect that it will run the all unit tests under /test forder.
I redirected the build process and stored into an output file and tried to find out unit tests by the name. However, I wasn't able to find some of the unit tests. It seems like some of the unit tests were actually not executed during the build process.
My question is how do I know the selection of unit tests that will be executed during the build process.
You may try explicitly naming the group(s) in the command line like this:
mvn clean install -Dtest.groups="unit,integration"
or simply
mvn test -Dtest.groups="unit,integration"
This is an example of what I use daily. My tests are either in the unit or the integration group. If you wish to run all (or some) tests without the need for explicitly specifying which gorups to use you have to modify your maven configuration though.
The unit tests in Maven will be selected by their name which should follow the naming convention
<includes>
<include>**/*Test*.java</include>
<include>**/*Test.java</include>
<include>**/*TestCase.java</include>
</includes>
Furthermore you need to put the tests to the default location src/test/java/.
You can control running only a single test by using:
mvn -Dtest=MyTest test
Running integration test is the job of the maven-failsafe-plugin which is handled in the integration-test phase. The naming convention for integration tests is:
<includes>
<include>**/*IT*.java</include>
<include>**/*IT.java</include>
<include>**/*ITCase.java</include>
</includes>
To get integration tests running you need to add a configuration part for the maven-failsafe-plugin.

Categories

Resources