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 ex开发者_运维百科ecute 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>
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.
You can do that simply in project properties. In NetBeans go to Project Properties, in right column select Actions. Here you can set properirtes for every action and every configuration (enviroment).
To skip tests add properties maven.test.skip=true
Updating for Netbeans 8:
- Right click on your project
- Select properties
- Go to Actions
- Select a Maven action
- Add the Skip Tests property
See the following image:
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.
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.
精彩评论