26

Is it possible to run junit tests in intelliJ in parallel? If so, how do i do this?

I set the "fork" parameter to class level and this didn't do anything - actually, it made everything a bit slower, so i'm unsure what "fork" does that is beneficial?

Is it possible to do this just using intelliJ, or do i need some fancy test framework and all the hoo-hah that that would involve?

Finally, assuming this is at all possible, can one control the number of forks or threads or whatever they want to call it?

UPDATE: somebody has linked to a question that might answer this. I looked at that question prior to posting - I'm unsure what that question really "answers". It simply says there is an issue tracker and that this issue has been implemented in intelliJ. I don't see how to implement it anywhere.

UPDATE: What does "didn't do anything" mean?: it just makes things slower, which isn't v. useful. I mean, maybe your tests run blazingly quickly and you want to slow them down to appreciate some Bach? That is cool. I just want mine to run faster, I'm fed up of Bach.

bharal
  • 15,461
  • 36
  • 117
  • 195
  • 1
    Define "it didn't do anything", it *does* do something, it runs your tests in a new JVM. That has *zero* to do with "running tests in parallel". – Dave Newton Apr 16 '13 at 16:43
  • Maybe using some maven support, as of http://stackoverflow.com/questions/423627/running-junit-tests-in-parallel. I understand it needs some maven hoo-hah, so I am not putting it as an answer. – HMM Apr 16 '13 at 17:50
  • @DaveNewton i suppose i meant "didn't do anything to alleviate the issue at hand". – bharal Apr 17 '13 at 08:50
  • @MarceloMorales yeah, i saw that - but the team run tests in intelliJ outside of ANT and - as somebody has linked as a dupe of this question - intelliJ claims to solve the problem. But I don't see how. – bharal 23 mins ago – bharal Apr 17 '13 at 09:16
  • A feature request has been added: https://youtrack.jetbrains.com/issue/IDEA-119553 – Eduard Wirch Jan 26 '15 at 10:07
  • Fork mode (as of IntelliJ 14.1) only runs it in a different process. This doesn't mean it will run in parallel. This also explains why it becomes slower. Because now it has to create a new process for each method. – Yamcha Apr 10 '15 at 13:29
  • "fork" means that there will be a new JVM created for each test run. This allows to make sure that your tests are not running into side effects like singletons that are initialized only once per classloader. – Slava Imeshev Jun 25 '15 at 19:44

1 Answers1

7

You can make use of the junit-toolbox. This is an extension library for jUnit that is listed on the jUnit site itself.

This extension offers the ParallelSuite. Through this you can create with nearly no effort an AllTest class that executes the tests in parallel. The minimum AllTest could look like the code below, using the pattern feature introduced with junit-toolbox.

@RunWith(ParallelSuite.class)
@SuiteClasses("**/*Test.class")
public class AllTests {}

This will create as many threads for parallel execution as your JVM reports via availableProcessors. To override this you may set the system property maxParallelTestThreads.

cheffe
  • 9,345
  • 2
  • 46
  • 57
  • 1
    you can give this plugin a try, it contains junit-toolbox in itself so that you can run your tests in parallel by just pressing a button inside IntelliJ: https://plugins.jetbrains.com/plugin/12959-junit4-parallel-runner – Csa77 Mar 25 '21 at 19:43