I have 2 sets of tests defined in Maven - integration-test and test.
If I run maven test - my tests run
If I run maven integration-test - both run
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<id>default-test</id>
<configuration>
<forkMode>always</forkMode>
<excludes>
<exclude>**/TC_Integration*</exclude>
</excludes>
<includes>
<include>**/TC_*</include>
</includes>
</configuration>
</execution>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/TC_Unit*</exclude>
</excludes>
<includes>
<include>**/TC_*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
What's the best way to make both run all the time? I mainly want maven install to run both, but it's not.
Instead of trying to configure surefire to run both unit and integration tests, configure surefire to run just the unit tests and use the failsafe plugin to run the integration tests.
https://maven.apache.org/surefire/maven-failsafe-plugin/
Related
How can I run the failed TestNG tests with maven failsafe plugin?
I run my tests with 'mvn clean install'.
When I run the tests and I get failing tests, I need to rerun them.
I do not have a testng.xml file and I think that this is also an issue.
This my pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<configuration>
<parallel>methods</parallel>
<threadCount>${threads}</threadCount>
<systemProperties>
<browser>${browser}</browser>
<screenshotDirectory>${project.build.directory}/screenshots</screenshotDirectory>
<remoteDriver>${remote}</remoteDriver>
<gridURL>${seleniumGridURL}</gridURL>
<desiredPlatform>${platform}</desiredPlatform>
<desiredBrowserVersion>${browserVersion}</desiredBrowserVersion> <!--Set properties passed in by the driver binary downloader-->
<!--Set properties passed in by the driver binary downloader-->
<phantomjs.binary.path>${phantomjs.binary.path}</phantomjs.binary.path>
<webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
<webdriver.ie.driver>${webdriver.ie.driver}</webdriver.ie.driver>
<webdriver.opera.driver>${webdriver.opera.driver}</webdriver.opera.driver>
</systemProperties>
<includes>
<!-- All that is left now is to clean up the code in our basicTest class and change its name to BasicTestWD. You may have noticed that we added an <includes> configuration item to our POM. This is because Maven will use maven-surefireplugin to run files that have test at the start or end of their name. We don't want maven-surefire-plugin to pick up our tests; we want to use maven-failsafeplugin instead. -->
<include>**/*WD.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.lazerycode.selenium</groupId>
<artifactId>driver-binary-downloader-maven-plugin</artifactId>
<version>1.0.7</version>
<configuration>
<rootStandaloneServerDirectory>
${project.basedir}/src/test/resources/selenium_standalone_binaries
</rootStandaloneServerDirectory>
<downloadedZipFileDirectory>${project.basedir}/src/test/resources/selenium_standalone_zips
</downloadedZipFileDirectory>
<customRepositoryMap>${project.basedir}/src/test/resources/RepositoryMap.xml
</customRepositoryMap>
<overwriteFilesThatExist>${overwrite.binaries}</overwriteFilesThatExist>
</configuration>
<executions>
<execution>
<goals>
<goal>selenium</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I use Coveralls in a Java project with Maven to create a coverage report for my project and I want to avoid some classes from being included in the coverage computation.
Now, I think that I the build phase I can exlcude the class, e.g. MyClassTest.java as follows:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
<configuration>
<excludes>
<exclude>**/*MyClassTest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.1.0</version>
</plugin>
Anyway, the coverage doesn't decrease, so I guess that the class MyClass is still computed from the Jacoco report.
In the travis file I call the report phase as follows:
- mvn clean test jacoco:report coveralls:report
Any idea?
My bad!
First the .java has to be removed and replace with .class as correctly suggested by Tunaki.
Second, I don't have to exclude the test class, but the class that I don't want to measure in the coverage!
So it is:
<excludes>
<exclude>**/*MyClass</exclude>
</excludes>
instead of
<excludes>
<exclude>**/*MyClassTest.java</exclude>
</excludes>
I have a set of integration tests which I need to run in specific order. So i created a BlahSuite.java inside the same package, and specified the order of classes there. And annotation as following
#RunWith(Suite.class)
#Suite.SuiteClasses({
And I added the plugin into pom as following
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.9</version>
<configuration>
<includes>
<include>**/*Suite.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
But still the tests are fired in different orders, feels like the Suite class is fully ignored. Any idea how to fix this ?
I found the answer at Stackoverflow question Run Junit Suite using Maven Command
So what my final setup is I just removed failsafe plugin and added following,
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Suite.class</include>
</includes>
</configuration>
</plugin>
We have a project with lots of tests running against a database. Many of the tests set up the database using #BeforeClass, and clean it out using #AfterClass, which works fine when we run the tests locally. When Jenkins runs them, it mixes up the order so tests from different classes are intermixed. For instance, A.TestAlpha, B.TestFoo, A.TestGamma. Then inevitably the tests fail because they don't have the correct setup.
My understanding of Jenkins is that it's supposed to run one class of tests at a time. Is there some config somewhere that might tell it to run the tests in this weird way?
(edit)
The same sort of problems occur running tests locally with mvn.
From mvn help:effective-pom
(project)
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<includes>
<include>**/When*.java</include>
<include>**/Test*.java</include>
<include>**/*Test.java</include>
<include>**/*TestCase.java</include>
</includes>
</configuration>
</plugin>
(module)
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/When*.java</include>
<include>**/Test*.java</include>
<include>**/*Test.java</include>
<include>**/*TestCase.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<includes>
<include>**/When*.java</include>
<include>**/Test*.java</include>
<include>**/*Test.java</include>
<include>**/*TestCase.java</include>
</includes>
</configuration>
</plugin>
Thanks to everyone who attempted to help.
The bug apparently lies in TestNG.
How to make sure TestNG runs methods on test classes in succession instead of interleaved?
I have two kinds of Unit tests (not integration test). Because of some strange behaviour with Spring Security I need to run first all normal tests, and later on the security tests.
I am using Junit (so I can not use any TestNG groups).
So what I have done is specify two sets of includes and excludes rules.
<excludes>
<exclude>**/*SecurityTest.java</exclude>
</excludes>
<includes>
<include>**/*Test.java</include>
<include>**/*Tests.java</include>
</includes>
and
<excludes>
</excludes>
<includes>
<include>**/*SecurityTest.java</include>
</includes>
That works if I replace them in my pom by hand so I can have normal or security tests. But of course I want that both kind of tests run in each build.
My first try was to have two complete maven-surefire-plugin configruation. But then maven take only the last of them in account.
My next try was to use two execution definitions, but then surefire seems to ignore the rules at all and run both kind of tests mixed.
So my general question is how to specify two file sets for maven surefire so that they will be executed each after another? And more specific how to specify two different file sets.
the configuration with executions
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<junitArtifactName>junit:junit</junitArtifactName>
<encoding>UTF-8</encoding>
<inputEncoding>UTF-8</inputEncoding>
<outputEncoding>UTF-8</outputEncoding>
<argLine>-Xms256m -Xmx512m -XX:MaxPermSize=128m -ea</argLine>
</configuration>
<executions>
<execution>
<id>normal-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/Abstract*.java</exclude>
<exclude>**/*_Roo_*</exclude>
<exclude>**/*SecurityTest.java</exclude>
</excludes>
<includes>
<include>**/*Test.java</include>
<include>**/*Tests.java</include>
</includes>
</configuration>
</execution>
<execution>
<id>security-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/Abstract*.java</exclude>
<exclude>**/*_Roo_*</exclude>
</excludes>
<includes>
<include>**/*SecurityTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
You haven't changed the default surefire execution which is bound to the test phase in the superpom, so it's still running with its default config. The id of that execution is "default-test". You'll either need to override it to unbind it from the test phase or else just use that id for one of your own executions.