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

前端 未结 3 1459
轮回少年
轮回少年 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.

提交回复
热议问题