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.
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.
Skipping by default by initializing the skipTests element value to true in properties and then overriding it through the command line by mentioning the value of -DskipTests in the maven phase/build execution command.
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
Instead of overriding the @Ignore
annotation, I did the following:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With