views:

36

answers:

3

I have a situation where our unit tests take a long time to execute for our business domain project as it sets up a database to a known state then proceeds to execute each step. I understand this can be done with "-Dmaven.test.skip=true" on the command line but wish to configure this within NetBeans for the project only, globally would be acceptable if anyone could clarify how to configure within the IDE.

How can I configure maven2 to only execute tests when the "test" target is called?

Using the following will disable tests even when the "test" target is called (from the maven docos).

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.6</version>
    <configuration>
      <skipTests>true</skipTests>
    </configuration>
  </plugin>
</plugins>
+2  A: 

http://maven.apache.org/general.html#skip-test

Just specify -Dmaven.test.skip=true when you invoke a target and don't want to execute tests.

Kyle W. Cartmell
Thank you Kyle, sorry I should have mentioned from my IDE (NetBeans)
Brett Ryan
A: 

on a project basis, the best way is to disable test execution by default and create a profile that enables it. Then in netbeans UI, open project properties Action panel and in the test, test file and debug test actions enable the profile.

mkleint
A: 

I see you've accepted an answer on this, but let me suggest an alternative.

The kind of test you're describing is an integration test... not a unit test. True, it's still an automated test, but it relies on an external resource and can take significantly longer to run. That's the earmark of an IT.

Maven is built to run integration tests separately for the very reasons you describe. The maven-failsafe-plugin is used for executing integration tests (*IT.java instead of *Test.java), and that plugin executes during the integration-test lifecycle phase (whereas surefire hooks the test phase).

Bottom line is that you can run all the way up to the package lifecycle without executing the longer-running tests.

Note that the install phase comes after integration-test, and that makes sense... if you're installing a new snapshot, you verify likely want to run your full test suite to ensure everything is working.

RonU