Search code examples
junitintellij-idea

Why does IntelliJ take 20+ seconds to launch a unit test?


In Eclipse, (if I remember correctly) I could run a JUnit test almost instantaneously with virtually no startup time. This meant I could do a codechange+test cycle in a couple of seconds.

I've recently migrating to IDEA IntelliJ, which seems to have to "make" the project before running a unit test if you've changed any source code since the last time. This typically takes 20 seconds for me, which is too long especially for test-driven development.

I can uncheck the "Make before launch" checkbox in the Run Configuration, but then the test is executed without compiling recent changes.

The warnings output during the "make" indicates that it is doing some aspect weaving for at least some of the time. I would imagine that aspects aren't generally wanted for unit testing.

My guess is that Eclipse was constantly compiling in the background every time you changed a source file, and doing so rapidly without doing the aspect weaving.

How can I speed up my codechange+test cycles in IntelliJ?

more info: I have "Compile in background" checked in Compiler Settings. The Java Compiler is ajc in com.springsource.org.aspectj.tools-1.6.8.RELEASE.jar


Solution

  • Pragmatic answer: switch the compiler from "ajc" to "Eclipse" during test-driven development. Remember to revert it when you're deploying the application!