How do I pass the test case to geb via maven commandline:
I have a test case class named GebishOrgSpec2.groovy
I want to pass this test case maven and let geb run it over the command line.
I am having successful build but no run of the test case
How do I solve this problem?
This is my pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<includes>
<include>${inc.TestCase}</include>
</includes>
<systemPropertyVariables>
<geb.build.reportsDir>target/test-reports/geb</geb.build.reportsDir>
</systemPropertyVariables>
</configuration>
</plugin>
I have tried the following codes and they are all not running the testcase
mvn -Dinc.TestCase=GebishOrgSpec2.groovy test
mvn -Dinclude=GebishOrgSpec2.groovy test
mvn install -Dinc.TestCase=GebishOrgSpec2.groovy
mvn install -Dinclude=GebishOrgSpec2.groovy
I have tried these links
How to run Geb TestCases from windows command line?
Grails geb getting parameters from commandline
Geb exception when running tests in maven
they are all not working
System.getProperty("inc.TestCase") is returning null as well
I want to add that if I add the test case directly into the pom it does run successfully
can you please help
Don't use in-/excludes in your POM for something you want to do from the command line. It is much easier, both for
Surefire (unit tests) via mvn -Dtest=TestCircle test and
Failsafe (integration tests) via mvn -Dit.test=ITCircle verify
This works beautifully for Spock/Geb tests.
Related
I'm facing some test time execution issue related to local test execution with Maven. I have around 250 tests which run about 15 min on the IDE test runner and about an hour (55min to be exact) when executing them with maven locally. I tried a lot of configurations to make test execution in parallel but neither of them work for me, the time is still the same...probably I'm doing something wrong. Can anyone help on this? The last maven surefire plugin configuration that I tried is the following:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<parallel>methods</parallel>
<threadCount>10</threadCount>
</configuration>
</plugin>
And for test execution command I've used:
mvn test
mvn surefire:test
Hi I am having a strange scenario.
I have a spring boot java project . I have lots of Junit tests as well.
when i run the tests from the terminal by issuing the command mvn clean test, 2 tests belong to a class fails
however if run the those tests belonging to that class from the eclipse Run as >> Junit tests it passes .
any idea why does this happens ? and how can i fix it ?
the following is my sure fire plugin configuration
<maven-surefire-plugin.version>2.18.1</maven-surefire-plugin.version>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<!-- Force alphabetical order to have a reproducible build -->
<runOrder>alphabetical</runOrder>
</configuration>
</plugin>
thank you
In my maven project I have a number of modules. Is it possible to turn off running unit test for some modules via command line options?
My project takes about 15 mins to run through all unit tests. I would like to speed up the overall build by running just the unit tests in the module I am working on. I do not want to go in and edit each individual pom.xml to achieve this.
I have tried a solution outlined here: Can I run a specific testng test group via maven? However the result is a lot of test failures in modules that I want to skip. I suppose 'group' is not the same concept of module?
To toggle unit tests on and off for an entire project use Maven Surefire Plugin's capability of skipping tests. There is a drawback with using skipTests from the command line. In a multi-module build scenario, this would disable all tests across all modules.
If you need more fine grain control of running a subset of tests for a module, look into using the Maven Surefire Plugin's test inclusion and exclusion capabilities.
To allow for command-line overrides, make use of POM properties when configuring the Surefire Plugin. Take for example the following POM segment:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<excludes>
<exclude>${someModule.test.excludes}</exclude>
</excludes>
<includes>
<include>${someModule.test.includes}</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<someModule.skip.tests>false</someModule.skip.tests>
<skipTests>${someModule.skip.tests}</skipTests>
<someModule.test.includes>**/*Test.java</someModule.test.includes>
<someModule.test.excludes>**/*Test.java.bogus</someModule.test.excludes>
</properties>
With a POM like the above you can execute tests in a variety of ways.
Run all tests (the above configuration includes all **/*Test.java test source files)
mvn test
Skip all tests across all modules
mvn -DskipTests=true test
Skip all tests for a particular module
mvn -DsomeModule.skip.tests=true test
Only run certain tests for a particular module (this example includes all **/*IncludeTest.java test source files)
mvn -DsomeModule.test.includes="**/*IncludeTest.java" test
Exclude certain tests for a particular module (this example excludes all **/*ExcludeTest.java source files)
mvn -DsomeModule.test.excludes="**/*ExcludeTest.java" test
Found a way to exclude on command line:
# Exclude one test class, by using the explanation mark (!)
mvn test -Dtest=!LegacyTest
# Exclude one test method
mvn verify -Dtest=!LegacyTest#testFoo
# Exclude two test methods
mvn verify -Dtest=!LegacyTest#testFoo+testBar
# Exclude a package with a wildcard (*)
mvn test -Dtest=!com.mycompany.app.Legacy*
This is from: https://blog.jdriven.com/2017/10/run-one-or-exclude-one-test-with-maven/
…and if you like to pass the parameter to maven release plugin in Hudson/Jenkins you have to use
-Darguments=-DskipTests
to get it work.
If you want to use Maven profiles:
http://maven.apache.org/guides/introduction/introduction-to-profiles.html
you might want to make it work doing something like this:
Skipping tests in some modules in Maven
I don't know if there is a supported command line option that does the same.
You also might try using environment properties directly, something as per this doc page:
http://maven.apache.org/plugins/maven-surefire-plugin/examples/skipping-test.html
i.e. something like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<skipTests>${moduleA.skipTests}</skipTests>
</configuration>
</plugin>
then using mvn -DmoduleA.skipTests=false test to test that one module.
Test output folder not created in target/surefire reports when I run as maven Test.
When i run my suite as maven test, surefire reports gets updated but test-output folder is not created. But when I run as Testng Suite, test-output folder is created.
what should I do to have test-output folder created on Run->Maven test?
When you run as Testng Suite you would be using Testng's default report location which is
${your base dir}/test-output
When you are running from maven, you are basically using Maven's surefire plugin to execute the testng tests. The reports output directory by default for surefire is
${your build directory}/surefire-reports
That is why you see the discrepancy in both runs.
To get the output in the same folder as testng does, you can explicitly specify the reports directory for the surefire plugin under the configuration section
<reportsDirectory>${basedir}/test-output</reportsDirectory>
and then run as maven-test to see the output there.
You can refer to the below link to see how to configure your pom's surefire plugin.
http://maven.apache.org/plugins/maven-surefire-plugin/examples/testng.html
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
I would like to know if there is a way to execute a goal when there is test failures?
Since maven stops its execution (fail fast mode) after encountering a test failure, is there any options to launch a goal when there is test failures?
Regards.
I've been searching for a way to do this as well, with not much success.
However, there is the following question which might provide some general hints:
Maven reporting plugins do not execute if a unit test failure occurs
The idea is that you would run mvn install (or whatever) first, and then run:
mvn -Dmaven.test.skip=true your-plugin:your-goal
This will let you run the build again without running tests, preserving the results for your perusal. Of course, this is only useful if your plugin is parsing the test results...
Though not recommended, by setting the surefire property testFailureIgnore to true, you can continue maven execution even when there are test failures.
...
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
...
<configuration>
<testFailureIgnore>true</testFailureIgnore>
...
</configuration>
</plugin>
...
Just do mvn clean install -DskipTests
I added this plugin in pom.xml and it worked well.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
If you want to the build to run KNOWING beforehand that there are going to be failures, you can use:
mvn <goal> -Dmaven.test.skip = true