Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set GWT headless mode in testing only for Maven?

I'm using Maven 3.0.3, GWT 2.4 on Linux. I want to set the GWT headless mode when running some tests (e.g. setting the -Djava.awt.headless=true). My question is, how do I set that parameter when running my GWT tests through Maven? I run my GWT tests by running

mvn clean test

Thanks, - Dave

like image 783
Dave Avatar asked Dec 05 '11 20:12

Dave


People also ask

How do I run only test cases in Maven?

If you want to run just a single test instead of all the tests declared in your project, create a Maven run configuration for a single test with the Maven -Dtest=TestName test command.

How do I exclude test cases in Maven?

To skip running the tests for a particular project, set the skipTests property to true. You can also skip the tests via the command line by executing the following command: mvn install -DskipTests.

Can Maven be used for testing?

maven-verifier-plugin simply verifies the existence/absence of files on the filesystem. You could use it for functional testing, but you may need more features than maven-verifier-plugin provides.

Which command of Maven is used to run all unit tests?

We can run our unit tests with Maven by using the command: mvn clean test. When we run this command at command prompt, we should see that the Maven Surefire Plugin runs our unit tests.


1 Answers

You can pass configuration parameters through the surefire plugin. Like:

<build>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.14</version>
  <configuration>
    <systemPropertyVariables>
      <java.awt.headless>true</java.awt.headless>
    </systemPropertyVariables>
  </configuration>
</plugin>
...

Reference: http://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html

The old version of this answer used the now deprecated "systemProperties" which you need to use for older surefire versions:

<build>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.14</version>
  <configuration>
    <systemProperties>
      <java.awt.headless>true</java.awt.headless>
    </systemProperties>
  </configuration>
</plugin>
...

For more configuration options check out the Surefire manual page: http://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html

like image 72
Christian Avatar answered Sep 21 '22 17:09

Christian