Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I force Intellij-IDEA to run an ignored test?

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 @Tests 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?

like image 808
Daniel Kaplan Avatar asked Jan 16 '14 23:01

Daniel Kaplan


People also ask

How do I run only failed test cases 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 .

How do I ignore tests in intelliJ?

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.

How do I run a specific junit test in intelliJ?

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.


1 Answers

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.

like image 140
Teresa Carrigan Avatar answered Oct 19 '22 19:10

Teresa Carrigan