Manish
Manish

Reputation: 3968

IntelliJ Idea "Make" causes rebuild while running JUnit Test

I am trying to move from Eclipse to Idea and having a hard time trying to execute JUnits. The application is a legacy application with 10k+ java classes.

Whenever I run any JUnit, either it takes 3-4 minutes to compile the test case and then executes it, or it gives a ClassNotFoundException for that particular JUnit class.

I have done a full build of the project (which takes about 9 minutes). I expect that after build only the modified files should be recompiled during "Make". And in my case, since I haven't changed any file, the JUnit should execute immediately.

I am using IntelliJ Idea 12 Community Edition and I have "Use External Build" checked in Compiler settings.

Am I missing any setting or doing anything wrong?

EDIT: While running the JUnit, I observed the output classes directory and it looks like it is deleting the generated classes and compiling them again!

Upvotes: 6

Views: 6043

Answers (3)

Piotr Pradzynski
Piotr Pradzynski

Reputation: 4535

When you save the JUnit configuration and then edit it you can edit the "before launch" section. You can remove "Make" from there and put "Make, no error check". This should speed up the build process and solve the issue.

Tested on IDEA 13.1.5

Upvotes: 1

Manish
Manish

Reputation: 3968

It turns out that IntelliJ IDEA does not like a single error in your whole project, even if the error is in some class which is totally unrelated to the test you are running. May be the Make process thinks the files containing compilation errors need to be recompiled. But even then why was it clearing the compiled classes and recompiling them is still a mystery to me.

The resolution to this problem was to make sure there is no error in your project. Once I fixed all the compilation errors and did a full rebuild, the tests now take about 2-3 seconds to launch.

Upvotes: 3

Javaru
Javaru

Reputation: 31936

Just to be sure we are using the terms compile, make, build and rebuild in the same manner, please refer to the Compilation Types in the Help Guide (Basic Concepts > Compiler and Builder > Compilation Types) or via its webhelp equivalent.

By default, when you run a unit test or application, IDEA does a Make and therefore should only compile classes that have changed since the last run. A potential gotcha (especially with legacy projects) lies in the dependency resolution. The make process will also compile any dependencies that have changed. If a project has some circular/crisscross dependencies, it can "confuse" the recursive dependency check and as a result a full module or modules cane be compiled. That may be the issue you are running in to.

It's possible a "less than ideal" dependency map could cause the recompile even if no files have changed. Keep in mind the make process should still run. It is that process that checks for modified classes and then launches the compile. But if no code has changed, that should only take a second or two. A couple of things to check/try: Verify that in your unit test run/debug configuration (Run > Edit Configurations) only has "Make" in its "Before Launch" section. (This should be the default and can be modified in the Default section in that dialog). Lastly, you can try invalidating the IDEA caches/indexes (File > Invalidate Caches) and restart IDEA. On restart IDEA will need to re-index your project and you will-need-to/should run another full rebuild. It's possible there is some corruption in the indexes that is causing the recompiling.

And just to check the obvious, make sure you are using the latest version of IDEA (12.1.6).

Upvotes: 0

Related Questions