问题
I have a JUnit test with an @Ignore attribute, for example -
public class HealthCareGov
{
@Test
@Ignore
public void performancetest()
{
// stuff
}
}
In most IDEs (IntelliJ for example) I can forcefully run this test by selecting the method name even though there is an @Ignore attribute. I'm guessing Eclipse also allows this?
However, when I try to do the same behavior in Maven by executing the following -
mvn -Dtest=HealthCareGov#performancetest test
It appears that Maven skips the test. This is the output -
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running HealthCareGov
Tests run: 1, Failures: 0, Errors: 0, Skipped: 1, Time elapsed: 0.032 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 1
What Maven command line can I use to force the execution of this test to reproduce the behavior that my IDE produces? Modifying the Java source code is not an option.
回答1:
This can be added to the test.
@IfProfileValue(name="test-profile", value="IntegrationTest")
public class PendingChangesITCase extends AbstractControllerIntegrationTest {
...
}
To select the tests to be executed just add the value to the profile for executing the integration tests.
<properties>
<test-profile>IntegrationTest</test-profile>
</properties>
Also, you can use the command line to set the test-profile variable:
mvn -Dtest-profile=IntegrationTest
回答2:
Instead of overriding the @Ignore
annotation, I did the following:
- Name your test that you wish to only run from the command-line outside of the standard maven test runner nomenclature (surefire or failsafe). This will ensure that your test does not get picked up by the regular maven lifecycle test execution.
- Write your test as normal, to include annotations for your framework on test methods.
When you wish to run your test, just include it manually by feeding it as a parameter to the runner.
-Dtest=Foo # for surefire
-Dit.test=Foo # for failsafe
This will force you to manually specify the test via a command-line argument when you want to run it, but omit the test otherwise.
来源:https://stackoverflow.com/questions/20637378/force-run-of-ignored-junit-test-using-maven-command-line