FAQs

Frequently Asked Questions

How do I pass property values as system properties from command line to tests run via Maven?

Maven adds an extra layer between the command line and the tests themselves. Two common plugins are used to run tests within Maven: maven-failsafe-plugin for integration tests and maven-surefire-plugin for unit tests. Both pass parameters the same way from command line:

mvn clean verify -DargLine="-DMyPropertyName=MyPropertyValue"

mvn clean verify instructs Maven to create a fresh build, run units tests (surefire), run integration tests (failsafe) and verify the tests passed.

-DargLine="-DMyPropertyName=MyPropertyValue" sets a System Property named argLine, instructing both plugins to include -DMyPropertyName=MyPropertyValue in the command when they invoke a new process to run the tests, resulting in passing system properties to those tests. Quotes are needed if there are any spaces.

Last updated