简体   繁体   English

TestNG:Eclipse被JUnit搞糊涂了

[英]TestNG: Eclipse confused by JUnit

I'm setting up tests with TestNG in an Eclipse project, but I get a strange error: When I try to generate a test class from a business class, I get a popup with a message saying "Grid not editable" (title) "The compilation unit is not compilable, or is not a sublcass of junit.framework.TestCase. Fix and tyr again" (body). 我在Eclipse项目中使用TestNG设置测试,但是我得到一个奇怪的错误:当我尝试从业务类生成测试类时,我得到一个弹出窗口,上面写着“Grid not editable”(标题)“编译单元不可编译,或者不是junit.framework.TestCase的次级。修复和tyr再次“(正文)。 Somehow, Eclipse seems to think I want to create JUnit classes, and I can't get why. 不知何故,Eclipse似乎认为我想创建JUnit类,我无法理解。 Any clue? 任何线索?

Configuration: 组态:

  • Eclipse 3.6.0 Eclipse 3.6.0
  • TestNG 5.14.10 TestNG 5.14.10

Google CodePro Analytix, the newly open-sourced static analysis tool, is the cause of the problem. Google CodePro Analytix是新开源的静态分析工具,是导致此问题的原因。 It creates a new default editor filter which tries to open each class which name ends with "Test" with its specific JUnit editor. 它创建了一个新的默认编辑器过滤器,它尝试打开名称以“Test”结尾的每个类及其特定的JUnit编辑器。 The TestNG plugin for Eclipse, on the other side, generates test classes using the tested class name, with "Test" added at the end. 另一方面,Eclipse的TestNG插件使用测试的类名生成测试类,最后​​添加“Test”。 So when you create a test class with the TestNG plugin, it's opened by default with CodePro Junit editor, which dispays an error popup saying the class is not a valid JUnit test class. 因此,当您使用TestNG插件创建测试类时,默认情况下会使用CodePro Junit编辑器打开它,该编辑器会显示一个错误弹出窗口,指出该类不是有效的JUnit测试类。 Solution is to remove the editor filter in Eclipse Preferences: 解决方案是删除Eclipse Preferences中的编辑器过滤器:

Window -> Preferences ; 窗口 - >首选项; General -> Editors -> File Associations 常规 - >编辑 - >文件关联

Select the *.java file type, pick Java Editor and click on the "Default" button. 选择* .java文件类型,选择Java Editor并单击“Default”按钮。

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

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