Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JUnit startup time is slow

I'm working on a fairly small project (in terms of dependencies), and whenever I run a unit test it takes 8 seconds for the JVM to load, before running the actual test in 0.2s.

My environment:

  • Java 8
  • Spring Tool Suite 3.8.1.RELEASE
  • JUnit 4
  • Windows 8

I fear there must be something in my environment that's causing this to take so long, and I'm hoping someone has seen this before and found the source of the problem and perhaps a solution?

E.g. if my PATH environment variable is really long, would that matter at all?

What exactly happens when I run a JUnit test?

The actual test I'm trying to run is:

public class TemplateLocationCalculatorTest {

    private TemplateLocationCalculator target = new TemplateLocationCalculator();
    
    @Test
    public void whenGivenRootReturnIndex(){
        Assert.assertEquals("index", target.calculate("/"));
    }
}

And the target class is this:

public class TemplateLocationCalculator {

    public String calculate(String string) {
        return "index";
    }

}

I hope you'll agree with me when I say this shouldn't take long to load.

like image 954
kinbiko Avatar asked Jan 18 '17 13:01

kinbiko


1 Answers

OP here.

Following a suggestion given in the chat I used the Microsoft Process Monitor and after a lot of filtering I discovered that the AV software Avecto DefendPoint was running on my machine, and that it seemed like this was the bottleneck. Whenever I start a test, it would run at about 25%, which to me seems to indicate that it's running at full speed on a single thread on one of my four cores. I'm not the administrator on this machine so I was unable to disable it to verify this hypothesis, but in general if other people should see this issue check if it could be your anti-virus software.

like image 74
kinbiko Avatar answered Oct 21 '22 11:10

kinbiko