Intellij IDEA fork mode for unit tests slows down
Asked Answered
K

2

11

I'm running 9 JUnit (Spockframework actually) tests in Intellij IDEA. It takes about 3 seconds.

I want to make use of all of the cores, therefore I switch test configuration fork mode - class. Edit configurations > Fork mode > class

This causes build time to grow to 8 seconds. Trying to use fork mode method makes it 22 seconds. Also test runner process looks like they are being run sequentially instead of in parallel.

Any ideas on why doesn't forking tests work as expected?

Killjoy answered 17/4, 2015 at 12:22 Comment(3)
I doubt you're going to beat 3 seconds no matter what you doUriel
@Uriel Sure, but it would be nice to have that as the test suite keeps growing.Killjoy
How do you know that you’re individual tests don’t already run on as many cores as possible? How do you know the time isn’t taken starting the JVM? How do you know the time isn’t spent classloading? Forking is generally used for test isolation not speed.Templeton
A
10

Forking just means you will get a separate process for each test run, but the process wilt not necessarily run in parallel.

From what I've seen, the JUnit plugin does not have an option to run tests in parallel. If you're using Gradle, use the maxParallelForks option as shown in the docs (and you probably know it, but you can run Gradle tasks directly from IntelliJ).

If you use Maven, try the -t option.

Aqaba answered 18/4, 2015 at 22:17 Comment(0)
E
1

You can give this plugin a try: https://plugins.jetbrains.com/plugin/16229-unit-test-parallel-runner

If you run unit tests in a single class, it runs all the test methods in parallel, if you run unit tests in many classes, it runs classes in parralel but methods in a single class are run in serial (it's faster this way unless you have a really high end machine).

Exploration answered 25/3, 2021 at 19:35 Comment(1)
Does not seem to work any longer in recent versions of Intellij such as 2023.1Mackenziemackerel

© 2022 - 2024 — McMap. All rights reserved.