Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 don't want to run integration tests written by my colleagues. Integration tests contain the text "IT", so I thought the following regex would do:

^((?!IT).)*$ 

But it didn't.

EDIT

As a trivial example, I tried the following regex:

^.*IT.*$

(which does exactly the opposite of what I want to achieve), but still I fail. It still picks up every single Test and runs it.

Example tests that get picked up:

com.my_company.session.SessionTest.java
com.my_company.test.server.api.ITAuthentication.java

enter image description here

This is what the Test results panel looks like

enter image description here

like image 797
kouretinho Avatar asked Mar 31 '17 15:03

kouretinho


People also ask

Why is IntelliJ not running tests?

Check in Project settings -> Modules that you test package is marked as Tests. Right click on the test class name either in the code window or in the project panel, and select Run <classname>. If you don't see the run menu in the popup then you haven't selected a test or you don't have junit plugin installed.

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.


Video Answer


1 Answers

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
like image 154
CrazyCoder Avatar answered Sep 17 '22 11:09

CrazyCoder