(some) JUnit test execution super slow

已回答

Yes, I have seen https://intellij-support.jetbrains.com/hc/en-us/community/posts/206257979-JUnit-execution-abysmally-slow , but that post is 8 years old, and doesn't give any hints what to do.

So: I am using the (always) latest version of IntelliJ community on MacOs.

We have a large project, with many test cases. Typically, a test class passes in 1, 2 seconds. 

But for me, since a few weeks, sometimes, a single test method needs 5+ seconds. So I easily look at 30 to 60 seconds for a single test class to finish.
The problem: other people, running the same test, with same IntelliJ on their local machines: < 1 second. 

Any idea how I could approach this, to figure why my tests run so slow?

0

Do you use Platform test runner? Do you use Maven/Gradle in project? Are there any background progress indicators shown when tests are launched?

There could be a proxy issue or slow dns resolve for the localhost, similar to https://stackoverflow.com/a/39698914/2000323 Check the solution mentioned in SO post. Try also deactivating all network interfaces and check. 

Try also using different JDK/Junit version.

0

Most of the time, I use

@RunWith(MockitoJUnitRunner.class)

No maven/gradle in our project. 

Update:

  • dropping network connectivity did not change anything
  • I then changed the jdk, but did just build+rerun ... still slow
  • I then changed the jdk back to what I had before. Quit intellij, and "build" again after restart ... my tests completed < 1 sec
  • I then did a "rebuild project" ... and tests are still completing as fast as they should.

So: the given recommendations did not help, but strangely enough, switching the JDK to a different one and back did the job.

 

1

Update: I am back to 6 seconds per test method ... and this time, switching the JDK doesn't help. 

0

Try with antivirus/firewall disabled or make sure that IDE settings/caches directories IDE installation home and project files are excluded from the scan.

Make sure you have correct network routing/dns settings including properly configured loopback (localhost) address.

0

No antivirus running on my machine. Beyond that, my overall setup didn't change, same machine, same connections, same everything when it worked as expected, and now, when it runs slower. 

Even more interestingly, some tests complete normally in ms, some take seconds.

0

What part takes time most? Process startup, the running tests itself?

You can profile the process by taking it's thread dumps with jstack: https://intellij-support.jetbrains.com/hc/en-us/articles/206544899

0

请先登录再写评论。