I'm trying to figure out why unit tests are taking seconds to run instead of milliseconds. This is a significant issue because over ~300 test classes, this results in 20 minutes. My hope is to use a performance analyzer (like java HPROF) with my maven unit tests. I would then analyze the hprof output on my own.
Asked
Active
Viewed 693 times
2
-
If you run the tests via maven you will get an output how each test class is taking to run the tests..afterwards you can dive into the classes with the most time consuming tests... – khmarbaise Aug 26 '17 at 08:37
-
Yeah. The issue wasn't that there's a particular slow test class. It was all of them :( – joseph Aug 28 '17 at 17:38
1 Answers
4
I added the below argline config to my surefire plugin block
<configuration>
<forkMode>never</forkMode>
<argLine>
-agentlib:hprof=cpu=samples,lineno=y,depth=3,file=hprof.samples.txt
</argLine>
...
<configuration>
You must not fork JVMs. All tests have to reuse the same jvm for this to work.
That generates an hprof file (see: https://docs.oracle.com/javase/7/docs/technotes/samples/hprof.html ). That gives you hints on what part of the code is slowing things down. In my case it was a combination of reuseFork=never and class loading.

joseph
- 2,429
- 1
- 22
- 43