Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 487
spikemanuk Avatar asked Oct 27 '11 08:10

spikemanuk


People also ask

How do I stop a running test in IntelliJ?

Stop tests Click. or press Ctrl+F2 to terminate the process immediately. Click. to terminate the process gracefully, allowing shutdown hooks to run.

How do I run a single JUnit test in IntelliJ?

Show activity on this post. Open the class where the tests are located and check the part where inteliJ shows the the number of lines, at the beginning of each test method there is a green icon (looks like a play button) just hit that icon and the specific test method will be executed.

Does IntelliJ have JUnit testing?

IntelliJ IDEA Unit Test We can run all unit tests inside the IntelliJ IDEA. IntelliJ IDEA has various unit testing frameworks like JUnit, TestNG and many more. In this section, we will understand how unit test work.

How does IntelliJ IDEA run tests?

Generally, IntelliJ IDEA runs and debugs tests in the same way as other applications, by running the run/debug configurations you have created. When doing so, it passes the specified test classes or methods to the test runner. In many cases, you can initiate a testing session from a context menu.

How do I run an autotest in IntelliJ?

Rerun tests automatically In IntelliJ IDEA, you can enable the autotest-like runner: any test in the current run configuration restarts automatically after you change the related source code. Click Toggle auto-test on the Run toolbar to enable the autotest-like runner.

What is a temporary run configuration in IntelliJ?

When you run a test, IntelliJ IDEA creates a temporary run configuration. You can save temporary run configurations, change their settings, share them with other members of your team.


2 Answers

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

like image 174
spikemanuk Avatar answered Oct 21 '22 02:10

spikemanuk


The options i activated in IntelliJ, speeding up tests execution from 20s to 2.5s:

Compiler

  • Make project automatically
  • Compile independend modules in parallel

Compiler -> Java Compiler

  • Use compiler: Eclipse
  • Generate no warnings
like image 38
PaoloC Avatar answered Oct 21 '22 00:10

PaoloC