When using surefire to run unit tests, it usually starts a new JVM to run tests, and we need to pass information to the new JVM. This can usually be done using the "systemPropertyVariables" tag.
Java- , POM:
<profiles>
<profile>
<id>special-profile1</id>
</profile>
<profile>
<id>special-profile2</id>
</profile>
</profiles>
:
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<systemPropertyVariables>
<profileId>${project.activeProfiles[0].id}</profileId>
</systemPropertyVariables>
</configuration>
</plugin>
...
</plugins>
</build>
unit test :
public void testApp()
{
System.out.println("Profile ID: " + System.getProperty("profileId"));
}
"test" (.. mvn test) :
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.fxs.AppTest
Profile ID: development
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.003 sec - in com.fxs.AppTest
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
mvn -P special-profile2 test,
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.fxs.AppTest
Profile ID: special-profile2
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 sec - in com.fxs.AppTest
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
. , , , .
. , Maven 3.1.1