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

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

Logging level under maven surefire

I tried setting java.util.logging.config.file in the MAVEN_OPTS environment variable, which does not work but finally got it working by putting that system property in the pom.xml (and of course creating an appropriate logging.properties in src/test/resources): <plugins> <plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> <systemProperties> <property> <name>java.util.logging.config.file</name> <value>src/test/resources/logging.properties</value> </property> </systemProperties> </configuration> </plugin> </plugins>

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.

Maven 2.1.0 not passing on system properties to Java virtual machine

I don’t think this is a problem in either Maven or Surefire plug-in. Else the surefire is behaving differently. It looks like now, when Surefire forks the JVM, will not take all the system properties from the parent JVM. That’s why you should pass whatever system properties you want for the tests, using argLine. So, … Read more

Setting timezone for maven unit tests on Java 8

Short answer Java now reads user.timezone earlier, before surefire sets the properties in systemPropertyVariables. The solution is to set it earlier, using argLine: <plugin> … <configuration> <argLine>-Duser.timezone=UTC</argLine> Long answer Java initializes the default timezone, taking user.timezone into account the first time it needs it and then caches it in java.util.TimeZone. That now happens already when … 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