简体   繁体   English

IntelliJ Idea“Make”导致在运行JUnit Test时重建

[英]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. 我正试图从Eclipse迁移到Idea并且很难尝试执行JUnits。 The application is a legacy application with 10k+ java classes. 该应用程序是一个具有10k + java类的遗留应用程序。

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. 每当我运行任何JUnit时,要么编译测试用例需要3-4分钟然后执行它,要么为该特定的JUnit类提供ClassNotFoundException。

I have done a full build of the project (which takes about 9 minutes). 我完成了项目的全部构建(大约需要9分钟)。 I expect that after build only the modified files should be recompiled during "Make". 我希望在构建之后,只应在“Make”期间重新编译修改过的文件。 And in my case, since I haven't changed any file, the JUnit should execute immediately. 在我的情况下,由于我没有更改任何文件,JUnit应该立即执行。

I am using IntelliJ Idea 12 Community Edition and I have "Use External Build" checked in Compiler settings. 我正在使用IntelliJ Idea 12社区版,我在编译器设置中选中了“使用外部版本”。

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! 编辑:在运行JUnit时,我观察了输出类目录,看起来它正在删除生成的类并再次编译它们!

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. 事实证明,IntelliJ IDEA不喜欢整个项目中的单个错误,即使错误在某个类中与您正在运行的测试完全无关。 May be the Make process thinks the files containing compilation errors need to be recompiled. 可能是Make进程认为需要重新编译包含编译错误的文件。 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. 一旦我修复了所有编译错误并进行了完全重建,现在测试需要大约2-3秒才能启动。

When you save the JUnit configuration and then edit it you can edit the "before launch" section. 保存JUnit配置然后编辑它时,您可以编辑“启动前”部分。 You can remove "Make" from there and put "Make, no error check". 你可以从那里删除“Make”并输入“Make,no error check”。 This should speed up the build process and solve the issue. 这应该加快构建过程并解决问题。

Tested on IDEA 13.1.5 在IDEA 13.1.5上进行了测试

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 . 为了确保我们以相同的方式使用术语compile,make,build和rebuild ,请参阅帮助指南中的编译类型基本概念>编译器和构建器>编译类型 )或通过其webhelp等效项

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. 默认情况下,当您运行单元测试或应用程序时,IDEA会执行Make ,因此应该只编译自上次运行以来已更改的类。 A potential gotcha (especially with legacy projects) lies in the dependency resolution. 潜在的问题(尤其是遗留项目)存在于依赖性解决方案中。 The make process will also compile any dependencies that have changed. make进程还将编译已更改的所有依赖项。 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. 请记住,make过程仍应运行。 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. 最后,您可以尝试使IDEA缓存/索引无效文件>无效缓存 )并重新启动IDEA。 On restart IDEA will need to re-index your project and you will-need-to/should run another full rebuild. 在重新启动时,IDEA将需要重新索引您的项目,您将需要/应该运行另一个完全重建。 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). 只是为了检查明显,请确保您使用的是最新版本的IDEA(12.1.6)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM