Excluding tests from being run in IntellIJ
Asked Answered
C

4

82

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.

Clavus answered 27/10, 2012 at 21:29 Comment(0)
C
138

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

Compiler answered 27/10, 2012 at 22:42 Comment(3)
Thanks for the tip! This works fine in IDEA, but causes all tests to be skipped under TeamCity. It seems that TeamCity 8.0.4 doesn't honor Pattern configurations at all. Should I file an issue?Sanguinary
Use pattern ^(?!(.*SlowTest$|.*SlowSpec$)).*$ to omit both slow Junit tests and Spock tests named with convention of .*SlowTest and .*SlowSpecAirtoair
btw, regex can be simplified to .*(?<!IT)$Redeploy
D
21

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.

Dispersion answered 19/6, 2018 at 11:5 Comment(1)
Take a look at this answer for details (including screenshot).Formalize
F
4

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.

Frustule answered 27/10, 2012 at 21:32 Comment(0)
R
0

For modern versions (2024) of IntelliJ, look here to include or exclude by JUnit tag:

Select Tags from type of resource dropdown

Rowles answered 12/7 at 21:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.