title: JUnit Tests: Why is Maven (Surefire) so much slower than running on Eclipse?
body: <p>I'm working on a fairly big application, with ~260k LOC and roughly 1800 unit tests on the suite. A little background:</p>
  
  <ol>
  <li>Multi-modular Maven project</li>
  <li>All tests run on a separate module and JaCoCo is used to check coverage.</li>
  <li>Tests are put together in some suites and then the suites are included on Surefire's configuration.</li>
  <li>Using <code>SpringJUnit4ClassRunner</code> to run the tests</li>
  <li>Surefire is currently configured to use the same VM to build and test (<code>forkCount</code>equals one and <code>reuseForks</code> equals true). Doing this I am sure I'm using the advantages of Spring's Static Context Cache (reuse the same <code>ApplicationContext</code> on every test)</li>
  </ol>
  
  <p>When we run tests on our development VMs, using Oracle JDK 7u79/80 we see very fast tests. For example, a fairly big test class with 50+ test methods takes something around 1:30m (including context initialisation time) to run. </p>
  
  <p>Our basic Dev VM is something like:</p>
  
  <ul>
  <li>Dual-Core i5 processor (with HyperThreading, so 4 virtual threads)</li>
  <li>8GB RAM</li>
  <li>Mid Range, SATA HDD (5k or 7k2 RPM)</li>
  <li>Windows 7 x64 running <strong>Oracle JDK on Client mode</strong> (-client)</li>
  </ul>
  
  <p>We use Jenkins as our CI server and Maven (3.2) takes care of the build process. We have a Master + 2 Slaves architecture. All the VMs are exactly the same:</p>
  
  <ul>
  <li>8 Xeon E5 Cores (Real cores)</li>
  <li>8 GB RAM</li>
  <li>SSD LUN serving the VMs (1.2GB/s mean throughput)</li>
  <li>Debian Linux 8 x64</li>
  <li><strong>Oracle JDK on Server mode</strong></li>
  </ul>
  
  <p>Remember those tests that usually take 1:30 min to run on our Eclipse's? Here on the server they take more than 15 minutes to run! Here's what I already tried to do (without success so far.):</p>
  
  <ul>
  <li>Set MAVEN_OPTS with fixed heap size (2GB heap), large PermGen space, tuned GC settings, /dev/urandom as random seed</li>
  <li>Installed a 32 bits JDK to use the same Client mode we use on the Dev Machines</li>
  <li>Tuned  on Surefire's configuration to increase memory, tune GC, etc. (As I'm not using a forked VM to run the tests anymore I took it out because it wouldn't change anything.)</li>
  </ul>
  
  <p>Bottom line, is there any concrete reason on why Surefire's execution is s much slower than running JUnit on Eclipse? I'm scratching my head over this for a few days now and it's really starting to annoy me! I hate it when the solution seems to be so close but yet it is so far.</p>
  
  <p>I couldn't test with Maven on my Dev machine because I couldn't allocate all the memory necessary to do it, but running chunks of classes (not the whole 1.8k tests suite) still reveals to be quite slower than running on Eclipse.</p>
  
  <p>I understand Maven has all those phases and so on, but the difference should't be this big. Don't you agree?</p>
  
  <p>Any input will be highly appreciated. I can provide any more information you find necessary!</p>
  
  <p>PS: Surefire v2.17, Maven 3.2.2, JUnit 4.12, Spring Test 3.2.13</p>
  
  <p>Thanks a lot!</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>I tried deactivating JaCoCo on the CI server to see if it affected the build times. It doesn't. The execution times remain the same.</p>