How to pass java code a parameter from maven for testing

This is the exact thing I was looking for my automation test and I got it working. Command Line argument mvn clean test -Denv.USER=UAT -Dgroups=Sniff My Pom Xml <?xml version=”1.0″ encoding=”UTF-8″?> <project xmlns=”http://maven.apache.org/POM/4.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”> <modelVersion>4.0.0</modelVersion> <groupId>TestNg</groupId> <artifactId>TestNg</artifactId> <version>1.0</version> <dependencies> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.8</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.12.4</version> <configuration> … Read more

Surefire is not picking up Junit 4 tests

mvn -X helped me to reveal the following: … [INFO] [surefire:test {execution: default-test}] [DEBUG] dummy:dummy:jar:1.0 (selected for null) [DEBUG] org.apache.maven.surefire:surefire-booter:jar:2.4.3:runtime (selected for runtime) [DEBUG] org.apache.maven.surefire:surefire-api:jar:2.4.3:runtime (selected for runtime) [DEBUG] Adding to surefire booter test classpath: /home/mindas/.m2/repository/org/apache/maven/surefire/surefire-booter/2.4.3/surefire-booter-2.4.3.jar [DEBUG] Adding to surefire booter test classpath: /home/mindas/.m2/repository/org/apache/maven/surefire/surefire-api/2.4.3/surefire-api-2.4.3.jar [DEBUG] dummy:dummy:jar:1.0 (selected for null) [DEBUG] org.testng:testng:jar:jdk15:5.8:test (selected for test) [DEBUG] … Read more

Is there a way to tell surefire to skip tests in a certain package?

Let me extend Sean’s answer. This is what you set in pom.xml: <properties> <exclude.tests>nothing-to-exclude</exclude.tests> </properties> <profiles> <profile> <id>fast</id> <properties> <exclude.tests>**/*Dao*.java</exclude.tests> </properties> </profile> </profiles> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <excludes> <exclude>${exclude.tests}</exclude> </excludes> </configuration> </plugin> Then in CI you start them like this: mvn -Pfast test That’s it.

JUnit tests pass in Eclipse but fail in Maven Surefire

I had the same problem (JUnit tests failed in Maven Surefire but passed in Eclipse) and managed to solve it by setting forkMode to always in the maven surefire configuration in pom.xml: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.12</version> <configuration> <forkMode>always</forkMode> </configuration> </plugin> Surefire parameters: http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html Edit (January 2014): As Peter Perháč pointed out, the forkMode parameter is … Read more

Run JUnit Tests contained in dependency jar using Maven Surefire

There is a way of running a test in maven from another jar. from maven-surefire-plugin version 2.15 you can tell maven to scan your test jars for tests and run them. You don’t need to extract the tests jar. Just add a dependency to your test jar and: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <dependenciesToScan> <dependency>test.jar.group:test.jar.artifact.id</dependency> </dependenciesToScan> … Read more

How do I get my Maven Integration tests to run

The Maven build lifecycle now includes the “integration-test” phase for running integration tests, which are run separately from the unit tests run during the “test” phase. It runs after “package”, so if you run “mvn verify”, “mvn install”, or “mvn deploy”, integration tests will be run along the way. By default, integration-test runs test classes … Read more