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

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.

enter image description here

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.


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.*).*$

Exclude 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