I pretty much only use JUnit Categories for non-unit tests that I don't want to run as part of the test suite. In NUnit I could use Explicit, but the only thing I've found comparable in JUnit is a Category. In gradle, it's simple to exclude a Category, but I can't figure out how to do this with IntelliJ's test runner. I see how to run tests that belong to a Category, but not how to exclude them.
Asked
Active
Viewed 1,670 times
11
-
1I don't think IntelliJ's built-in test runner is intelligent enough to handle this by itself. Ever consider delegating that action to Gradle instead? – Makoto Jul 05 '17 at 14:48
-
When I need to do this, it's specifically to not use gradle, e.g. troubleshooting, debugging – Novaterata Jul 05 '17 at 14:52
-
For example, there are bugs that manifest as the gradle test runner either failing silently or hanging indefinitely. It's much easier to pin point the problem with a GUI – Novaterata Jul 05 '17 at 14:54
-
You can specify a category in the debug configuration for a test: https://www.jetbrains.com/help/idea/run-debug-configuration-junit.html However, it looks like there is no way to exclude a category. – matt helliwell Jul 09 '17 at 10:14
-
It's work in progress: https://youtrack.jetbrains.com/issue/IDEA-153780 . You can upvote the issue to make it a bit higher priority. – Pieter De Bie Jul 30 '19 at 08:30
-
1@Pieter De Bie thanks, I'm one of the participants in the comments. I've switched to always using Gradle to run tests, which supports the scenario via custom test tasks. – Novaterata Jul 30 '19 at 19:30
1 Answers
1
Some time has passed since I asked this question, and in that time the Gradle test runner has become the default (at least for me). So though the built-in runner may not have this functionality, you can easily create a gradle task that excludes categories or tags:
test {
useJUnitPlatform {
excludeTags 'integrationTest'
excludeTags 'endToEndTest'
excludeTags 'testDriver'
}
options {
exclude '**/*Integration*'
exclude 'integrationTest'
exclude 'endToEndTest'
exclude 'testDriver'
}
}

Novaterata
- 4,356
- 3
- 29
- 51