3

I have in pom the plugin maven-surefire-plugin with skipTests on true. However, sometimes I want to run the tests from the command line and I want to overwrite this plugin from command line and to leave the pom file unchanged.

I tried

mvn install -DskipTests=false
but it still skips the tests...

Any idea how I can solve my problem...?
Thanks

2 Answers 2

7

Skipping by default is specifically discussed in the plugin documentation:

If you want to skip tests by default but want the ability to re-enable tests from the command line, you need to go via a properties section in the pom

In other words use a property for the default:

 <configuration> <skipTests>${skipTests}</skipTests> </configuration> 

Define a property:

 <properties> <skipTests>true</skipTests> </properties> 

Properties can be overridden from the command-line:

 mvn install -DskipTests=false 

Note that the skipTests in the command-line above refers to the property, not to the plugin parameter with the same name.

Sign up to request clarification or add additional context in comments.

1 Comment

The property can only be overridden by using this placeholder in pom.xml The updated ref: maven.apache.org/plugins-archives/maven-surefire-plugin-2.12.4/…
0

Using profile can do the trick. It requires you change the pom file though it gives you the behaviour you want.

Set a property in project element

<properties> <runtests>false</runtests> </properties> 

Now create a profile

 <profile> <id>run-tests</id> <properties> <runtests>true</runtests> </properties> </profile> 

in surefire plugin configuration

<skipTests>${runtests}</skipTests> 

Now run mvn install -P run-tests This command will activate the profile, thus set the runtests property to true

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.