简体   繁体   English

在IntelliJ中运行JUnit而忽略不相关类中的编译错误?

[英]Run JUnit in IntelliJ while ignoring compilation error in an unrelated class?

When running a JUnit test case in IntelliJ it opens up the Make console and shows complication errors in an unrelated class. 在IntelliJ中运行JUnit测试用例时,它会打开Make控制台并显示不相关类中的复杂错误。

  1. Can I run the test case ignoring these errors? 我可以运行测试用例忽略这些错误吗?

  2. Is there a way to make it not compile the entire project when running the test cases but only those class files required by the test case? 有没有办法让它在运行测试用例时不编译整个项目,而只测试测试用例所需的那些类文件?

Yes you can. 是的你可以。

You can disable the Make before Run. 您可以禁用“运行前制作”。

(The following is written for IntelliJ 14, different versions might have slightly different layouts, but as far as I can remember these options have been the same for a while) (以下是针对IntelliJ 14编写的,不同版本的布局可能略有不同,但据我记忆,这些选项暂时相同)

For a single test 对于单个测试

  • Go to "Run" - "Edit Configurations..." 转到“运行” - “编辑配置...”
  • Select the configuration of your test case 选择测试用例的配置
  • In the tab named "Configuration" there is a List "Before Launch" with one entry "Make". 在名为“Configuration”的选项卡中,有一个列表“Before Launch”,其中包含一个条目“Make”。 Remove that entry. 删除该条目。
  • Confirm with "OK" 单击“确定”确认

For all tests: 对于所有测试:

If you want to remove this by default for all new test configurations (which might not be a terribly good idea, since then you got to allways build manually when running tests) 如果你想在所有新测试配置中删除它(这可能不是一个非常好的主意,从那时起你必须在运行测试时手动构建)

  • Go to "Run" - "Edit Configurations..." 转到“运行” - “编辑配置...”
  • Select "Defaults" in the Tree 在树中选择“默认值”
  • Select your Testframework (Junit or TestNG most probably) 选择你的Testframework(最有可能是Junit或TestNG)
  • In the tab named "Configuration" there is a List "Before Launch" with one entry "Make". 在名为“Configuration”的选项卡中,有一个列表“Before Launch”,其中包含一个条目“Make”。 Remove that entry. 删除该条目。
  • Confirm with "OK" 单击“确定”确认

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

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