In IntelliJ IDEA, can I run only tests matching a regex pattern?

前端 未结 3 1448
轮回少年
轮回少年 2020-12-19 09:20

is it possible to create a Run/Debug configuration in IntelliJ that picks up only those files that match a regular expression?

I want to run all my unit tests. I do

相关标签:
3条回答
  • 2020-12-19 09:36

    Short answer:

    doesn't work with JUnit 5

    Long answer

    CrazyCoder kindly responded to my post on Jetbrain's forum. He provided an answer and also uploaded his working project. That was helpful because I verified that pattern matching worked fine on his project.

    Then another Jetbrain engineer responded to my How-To request. He pointed out IDEA-164088, JUnit 5 doesn't support pattern configurations

    That's a known issue and will be fixed on versions 2017.2.X coming up on April 2017.

    Solution

    A workaround until then, is to use JUnit5 tags

    @Tag("junit")
    public class MyTest 
    

    and then run the following configuration that only picks up test classes annotated with that particular tag.

    P.S. Actually, using Tags seems an even more elegant solution for the given task as long as the number of test classes is limited.

    0 讨论(0)
  • 2020-12-19 09:36

    You can run all test case in a class, after that >> select some test case by hold Ctrl and click mouse >> run, then open config run and copy the pattern to edit more..

    0 讨论(0)
  • 2020-12-19 09:49

    I've already provided the answer which describes how to exclude *IT.java tests, but as your question is different and you want to exclude *IT*.java tests (any test that has IT in its name), the pattern would be different:

    ^(?!.*IT.*).*$
    

    Note that it will not work with JUnit 5 in IntelliJ IDEA 2017.1, there is a known bug that is fixed for 2017.2 version:

    • IDEA-164088 JUnit 5 doesn't support pattern configurations
    0 讨论(0)
提交回复
热议问题