Reputation: 2507
I try to set up properties in my pom.xml and access them during my jUnit test.
The class I want to read them in, is imported by the jUnit Test.java
and is using
String prop = System.getProperty("target1");
but it always is null. What I tried in my pom.xml already:
...
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<target1>2948</target1>
</properties>
</profile>
</profiles>
and also
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.15</version>
<systemPropertyVariables>
<target2>2948</target2>
</systemPropertyVariables>
<systemProperties>
<property>
<name>target3</name>
<value>2948</value>
</property>
</systemProperties>
...
</configuration>
...
I do have a parent pom.xml but that can't be the problem can it? I'm using Netbeans and starting the Tests by hiting "Test File" on the pom.xml
Thanks yous :)
Upvotes: 3
Views: 10203
Reputation: 1174
I don't know about maven-failsafe-plugin, but I am able to get the result by adding property and value in maven-surefire-plugin since that is what is used by junit tests in a maven project. Here is a detailed explanation: Specify system property to Maven project
from the maven site (http://maven.apache.org/surefire/maven-failsafe-plugin/) - "The Failsafe Plugin is designed to run integration tests while the Surefire Plugins is designed to run unit tests". Since you are running a junit, you should add your property to surefire plugin.
Upvotes: 1