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?
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.
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.
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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With