I wrote a performance test class marked as @Ignore
because it takes a very long time to run and I don't normally need to run it. I'd like to be able to right click one of the @Test
s and say "run" but when I do that in intellij it doesn't run the test because the class is marked as ignored.
I don't want to comment out the @Ignore
because it's too easy to accidentally commit the file with the @Ignore
removed. But I feel that if I explicitly tell Intellij to run a test it should run it regardless of the @Ignore
. Keep in mind, if I run a group of classes (eg: all in a package) I still would want this test class to be ignored.
Is it possible to get this functionality in Intellij?
If you want to rerun a failed test, I would suggest to first filter the test results to show only failed tests. Then you right click your test(s) you want to rerun and select Run {testMethodName} or press Ctrl + Shift + F10 .
to toggle the Skip tests mode. On the Runner page, select Skip tests and click OK. IntelliJ IDEA de-activates the test goal under the Lifecycle node. The appropriate message notifying that tests are skipped is displayed in the Run tool window when you execute other goals.
Show activity on this post. Open the class where the tests are located and check the part where inteliJ shows the the number of lines, at the beginning of each test method there is a green icon (looks like a play button) just hit that icon and the specific test method will be executed.
I found this link which says that you can do something tricky with Assume.assumeTrue that will mark the test as ignored if the condition is false, and normally this is a system property that is used in the condition, so you can pass it in as a parameter on the command line. IntelliJ lets you customize the command line parameters, so it should work, but I haven't tried it myself.
The example from the link is:
@Test
public void shouldTryEveryPossiblePhoneticAttributeSet() throws IOException {
Assume.assumeTrue(TestEnvironment.hasBigParseSets());
...
}
public class TestEnvironment {
private static final String HAS_BIG_PARSESETS = "hasBigParseSets";
public static boolean hasBigParseSets(){
return "true".equalsIgnoreCase(System.getProperty(HAS_BIG_PARSESETS));
}
}
And "mvn test -P bigParseSets" vs "mvn test".
edit: And I just found this neat thread on StackOverflow that tells how to run a single junit test. I assume I don't need to quote that since it's to a post here on StackOverflow. That explains how to do it from a command line, but you should be able to do something very similar to that one that has hard coded values for the class and method names, and then just right click on the SingleJUnitTestRunner class and ask IntelliJ to run it.
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