I have multi module maven project. One parent and two submodules. In first module I have integration tests, specifically selenide tests, which are testing web application. Web application is in the second module. I want to deploy application via jetty server and then run selenide tests on it in one maven command. I have tried more solutions and here are few of them.
In the module with web app I set up jetty plugin to run server before tests.
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<contextPath>web-app</contextPath>
<stopPort>8005</stopPort>
<stopKey>STOP</stopKey>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
and failsafe-maven-plugin.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>failsafe-maven-plugin</artifactId>
<version>2.4.3-alpha-1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
But problem is that plugin not find any tests because they are in other module.
Can you tell me how to set up failsafe to find test in first module ? Or other solution for example run it from parent ?
Well, I'm not an expert, maybe JUnit #Rule is that can help you to solve your task: to initialise, deploy and test your web app.
Have a look at this:
How does Junit #Rule work?
JUnit Rules Wiki
Here is described Rule to start a Jetty Server
Related
I am integrating Flyway in to an existing legacy project, which consists of multiple databases for the same application. The project uses Maven and I want to use the maven-flyway-plugin to integrate with Flyway.
My working configuration so far looks like this:
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<executions>
<execution>
<id>db1</id>
<goals>
<goal>migrate</goal>
</goals>
<configuration>
...
</configuration>
</execution>
<execution>
<id>db2</id>
<goals>
<goal>migrate</goal>
</goals>
<configuration>
...
</configuration>
</execution>
<execution>
<id>db2</id>
<goals>
<goal>migrate</goal>
</goals>
<configuration>
...
</configuration>
</execution>
</executions>
</plugin>
With this I can migrate each database separately like this:
mvn flyway:migrate#db1 flyway:migrate#db2 flyway:migrate#db3
Unfortunately this is not very user friendly. I want to be able to simply execute mvn flyway:migrate and execute all three migration configurations.
How can I achieve that?
maven works this way. You can either extends flyway plugin with your needs or you can migrate to gradle which can gather multiple 'job'
Eric
In my pom.xml I have frontend-maven-plugin.
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<nodeVersion>v6.11.0</nodeVersion>
<npmVersion>3.10.10</npmVersion>
<workingDirectory>src/main/frontend</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<execution>
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
It takes some time to run it and don't need this plugin when I run tests.
Is it possible to not execute the plugin when I run mvn test?
The frontend-maven-plugin now has specific keys to disable execution of particular goals. For example, adding system property skip.npm will skip npm execution. You can add it when running maven this way:
mvn test -Dskip.npm
did you heard about maven profile?
http://maven.apache.org/guides/introduction/introduction-to-profiles.html
I understand that when you want to test a package, you don't want to build a bigger one.
You could define a profile that choose exactly what module you want to build and test.
You have a related question there:
Disable maven plugins when using a specific profile
Let us know if it helped you!
I just added Jacoco on my maven dependencies to run integration tests. Then, I created an integration test to test my controller. For example, I tested my HTTP response codes, the headers and the response resources. After that, I created a profile on maven that starts an embedded tomcat. So, everytime I want to run my integration tests, I just put the profile on the maven goals. However, when I execute the build on Jenkins and Sonar reads the reports from Jacoco, the reports says that I have not tested my controller. The question is: How I tell Jacoco that I have passed through my Controllers, Services and Repositories?
Thanks to all!
Are you getting any Integration Coverage, or just 0%?
It can be quite tricky to set up Integration Test Coverage using maven and Sonar.
Check there is a jacoco file produced when the IT tests are run.
Check your POM set up compared to this...
<properties>
<!-- Jacoco Properties -->
<jacoco.version>0.7.4.201502262128</jacoco.version>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.jacoco.itReportPath>${project.basedir}/target/jacoco-it.exec</sonar.jacoco.itReportPath>
<sonar.language>java</sonar.language>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>prepare-unit-test-agent</id>
<configuration>
</configuration>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>prepare-it-test-agent</id>
<configuration>
<propertyName>jacoco.agent.argLine</propertyName>
<destFile>${sonar.jacoco.itReportPath}</destFile>
<append>true</append>
</configuration>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<argLine>${jacoco.agent.argLine}</argLine>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Link to GitHub example
BeyondCoding.net
I use tomcat6-maven-plugin to run integration tests on my web application. This starts Tomcat and deploys my web application in it before running the tests. Works well!
But I'd like to run another web application, GeoServer, at the same time, for some new integration tests to work. What would be the best approach?
Is it possible to add a GeoServer .war to the Tomcat instance started using tomcat6-maven-plugin? How?
Here my current tomcat6-maven-plugin config :
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
<port>8087</port>
<fork>true</fork>
<useTestClasspath>true</useTestClasspath>
</configuration>
<executions>
<execution>
<id>run</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>shutdown</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>
</plugin>
I want to switch from KindleIT's to Google's App Engine Maven plugin. When using the KindleIT plugin, I launched the GAE dev server right in the pre-integration-test phase. I shutdown the dev server once the integration tests are complete in post-integration-test. We are using the surefire plugin to run our unit and integration tests.
<plugin>
<groupId>net.kindleit</groupId>
<artifactId>maven-gae-plugin</artifactId>
<version>0.9.5</version>
<executions>
<execution>
<id>gae-start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>gae-stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
I am doing that because I want to run integration tests agains the locally running GAE app. How can I do the same with Google's App Engine plugin?
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${gae.version}</version>
</plugin>
I want to use something like the
mvn appengine:devserver
goal. But this just launches the devserver in the foreground. I want Maven to launch the dev server in the background before the tests.
This isn't supported yet on the official plugin, but we're working on it and I'm hoping to get it into a snapshot build soon. I'll keep you posted, but this issue is where I'm tracking my work on that:
https://code.google.com/p/appengine-maven-plugin/issues/detail?id=5
Use maven-jetty-plugin. This plugin starts jettty instance and run your war/gae project.
you can run this plugin in pre-integration-test phase, then run integration test, and in the post-integration-test-phase the server will shutdown.
I´m working with gae application, and works fine with this plugin.
This is my configuration, i hope help you:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.15</version>
<configuration>
<contextPath>/</contextPath>
<scanIntervalSeconds>3</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
<connectors>
<connector implementation ="org.mortbay.jetty.nio.SelectChannelConnector" >
<port>${deploy.server.port}</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
In addition, maybe you´ll found this exection on execution:
Exception in thread "Shutdown" java.lang.NoClassDefFoundError: org/apache/jasper
/runtime/JspApplicationContextImpl
This will be solved adding this dependency to your pom.xml
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-2.1</artifactId>
<version>6.0.0</version>
</dependency>