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?

Wojtek Erbetowski
  • 3,205
  • 5
  • 22
  • 37
  • I doubt you're going to beat 3 seconds no matter what you do – tim_yates Apr 17 '15 at 17:30
  • @tim_yates Sure, but it would be nice to have that as the test suite keeps growing. – Wojtek Erbetowski Apr 19 '15 at 07:57
  • 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. – Boris the Spider Mar 25 '21 at 19:38

2 Answers2

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.

Renato
  • 12,940
  • 3
  • 54
  • 85
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).

Csa77
  • 649
  • 13
  • 19