简体   繁体   English

我可以强制Intellij-IDEA运行被忽略的测试吗?

[英]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. 我写了一个标记为@Ignore的性能测试类,因为它需要很长时间才能运行,我通常不需要运行它。 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. 我希望能够右键单击其中一个@Test并说“运行”,但是当我在intellij中执行此操作时,它不会运行测试,因为该类被标记为忽​​略。

I don't want to comment out the @Ignore because it's too easy to accidentally commit the file with the @Ignore removed. 我不想注释掉@Ignore因为它太容易不小心犯了该文件@Ignore删除。 But I feel that if I explicitly tell Intellij to run a test it should run it regardless of the @Ignore . 但是我觉得如果我明确地告诉Intellij运行测试它应该运行它而不管@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? 是否有可能在Intellij中获得此功能?

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. 我发现这个链接说你可以用Assume.assumeTrue做一些棘手的事情,如果条件是假的话会把测试标记为忽略,通常这是在条件中使用的系统属性,所以你可以把它传入命令行上的参数。 IntelliJ lets you customize the command line parameters, so it should work, but I haven't tried it myself. IntelliJ允许您自定义命令行参数,因此它应该可以工作,但我自己没有尝试过。

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". 并且“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. 编辑:我刚刚在StackOverflow上发现了这个简洁的线程 ,告诉我们如何运行单个junit测试。 I assume I don't need to quote that since it's to a post here on StackOverflow. 我假设我不需要引用它,因为它是在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. 这解释了如何从命令行执行此操作,但您应该能够执行与具有类和方法名称的硬编码值的操作非常类似的操作,然后右键单击SingleJUnitTestRunner类并要求IntelliJ运行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM