Excluding tests from being run in IntellIJ

JavaMavenJunitIntellij Idea

Java Problem Overview


Is it no option to exclude some tests in IntelliJ IDEA Ultimate? I want to run unit tests in IntelliJ but exclude the integration tests. I name the integration tests with *IT.java so the Maven failsafe plugin can run them seperatly from the unit tests.

Java Solutions


Solution 1 - Java

In the JUnit Run configuration set the Test kind to Pattern, specify the following regular expression as the pattern:

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

It matches against the class name, so you don't need to match .java extension. Regular expression will not match if the class name ends with IT using the negative lookahead.

ignore tests ending with IT

Solution 2 - Java

With JUnit5, you can now tag your tests, e.g: @Tag("integration-test").

Also, given IntelliJ supports now JUnit5 as well, you can then create a JUnit Test Configuration and select Test Kind: Tags (JUnit5).

To exclude let's say "integration-test", you just need to specify as tags: !integration-test, and IntelliJ will run all your JUnit5 tests except the ones tagged with integration-test.

Solution 3 - Java

I would split them to that they are in different packages. They are doing different things after all. You can then run your tests per package. This link details how to do this.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser626912View Question on Stackoverflow
Solution 1 - JavaCrazyCoderView Answer on Stackoverflow
Solution 2 - JavaJoão PinhoView Answer on Stackoverflow
Solution 3 - JavaRNJView Answer on Stackoverflow