Wednesday, May 30, 2012

Set System property on Maven pom.xml for test

Hi, I made maven test class that makes internet connection like Soap, http connection so on that verifies all test is successful. but, my local internet connection requires Proxy server configuration. If I run it on my computer, it won't run because I get connection refused error. If I set system property on my java source, it is not pretty and I might need to change source code when I deploy on production level.

There is the solution :
I need to add maven-surefire-plugin for setting system property on pom.xml file. That is only applies for test classes system property. You can set skip test if you change value of skipTests element true/false below

<project ...>
 <dependencies>
 ...
 </dependencies>

 <build>
    <plugins>
       <plugin> ....      </plugin>

       <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.12</version>
  <configuration>
    <skipTests>true</skipTests>
    <systemPropertyVariables>
      <http.proxyHost>106.101.5.61</http.proxyHost>
      <http.proxyPort>8080</http.proxyPort>
    </systemPropertyVariables>
  </configuration>
       </plugin>
     </plugins>  
 </build>
</project>


For more detail please refer maven surefire plugin document

No comments:

Post a Comment