java 在 IntelliJ 中运行 JUnit,同时忽略不相关类中的编译错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29535628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 15:26:53  来源:igfitidea点击:

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

javaintellij-idea

提问by Kshitiz Sharma

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?

  1. 我可以运行测试用例而忽略这些错误吗?

  2. 有没有办法让它在运行测试用例时不编译整个项目,而只编译测试用例所需的那些类文件?

回答by cbeutenmueller

Yes you can.

是的你可以。

You can disable the Make before Run.

您可以禁用 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". Remove that entry.
  • Confirm with "OK"
  • 转到“运行”-“编辑配置...”
  • 选择测试用例的配置
  • 在名为“Configuration”的选项卡中有一个“Before Launch”列表,其中包含一个“Make”条目。删除该条目。
  • 按“确定”确认

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)
  • In the tab named "Configuration" there is a List "Before Launch" with one entry "Make". Remove that entry.
  • Confirm with "OK"
  • 转到“运行”-“编辑配置...”
  • 在树中选择“默认值”
  • 选择您的测试框架(最有可能是 Junit 或 TestNG)
  • 在名为“Configuration”的选项卡中有一个“Before Launch”列表,其中包含一个“Make”条目。删除该条目。
  • 按“确定”确认