Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij IDEA fork mode for unit tests slows down

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?

like image 943
Wojtek Erbetowski Avatar asked Apr 17 '15 12:04

Wojtek Erbetowski


People also ask

Does IntelliJ run tests in parallel?

Answering late for posterity. You can make JUnit tests run in parallel (or serial) to any level of granularity in IntelliJ by changing the Fork mode in the test's run configuration. Be careful not to confuse this with the Allow parallel run option, which lets you start the test execution multiple times within your IDE.

Why is JUnit so slow?

The problem is that JUnit (or something in our tests or test runner) is doing a DNS lookup on the machine's hostname. That lookup should be really fast, but if you're connected to a VPN it may search the remote DNS server which takes time and makes the tests take much longer than they should.

What is toggle auto test in IntelliJ?

IntelliJ now actually has a Toggle auto-test in the run dialog. Just run a run-configuration and then select Toggle auto-test in the run dialog. It's not as intelligent as you would have hoped. It just reruns when it detects changes. Follow this answer to receive notifications.


2 Answers

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).

like image 69
Csa77 Avatar answered Sep 18 '22 14:09

Csa77


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.

like image 32
Renato Avatar answered Sep 19 '22 14:09

Renato