使用 Eclipse 创建新的 JUnit 测试用例
我有一个关于使用 Eclipse 为现有 Java 应用程序编写附加 JUnit 测试用例的问题。
有一个名为“pass”的文件夹,其中包含所有通过测试。我通过右键单击该文件夹并选择“新建”→“文件”来创建一个新的通过测试。但是,当我创建 JUnit 测试用例时,新测试不会显示为“被测类”下的选项。
如何在 pass 文件夹中创建此测试用例,使其显示为“被测类”中的选项?谢谢!
我尝试进行项目/清理和项目/重建,但没有帮助。
I have a question about using Eclipse to write an additional JUnit test case for an existing Java application.
There's a folder called "pass" which contains all of the pass tests. I create a new pass test by right clicking on the folder and selecting New → File. However, when I create the JUnit test case, the new test doesn't show up as a choice under the "class under test."
How do I create this test case in the pass folder in such a way that it will show up as as a choice in "class under test?" Thanks!
I tried doing a Project/Clean and Project/Rebuild, but it didn't help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
pass
必须是源文件夹,就像src
一样。然后,对被测类存在误解。这不是 JUnit 测试类,而是您要测试的类。通常,您将 Java 类和 JUnit 测试类配对,如下所示:导航器视图:
pass
has to be a source folder just likesrc
. Then, there is a misunderstanding concerning Class under test. This is not the JUnit test class but the class you want to test. Usually you pair a Java class and a JUnit Test Class like this:Navigator view:
右键单击->新-> JUnit 测试用例
从Java角度
Right-Click -> New -> JUnit Test Case
from Java Perspective
单击该文件夹时,选择“新建”>“类而不是文件(这会创建一个 Java 类)。然后将您的 Java 代码放入此类中。您可以通过使用 JUnit 注释或在方法名称上使用“test”前缀来显示各个测试。
然后,确保在重建后重新运行 JUNIT 配置(右键单击项目并运行为 Junit 测试)。
When you click on the folder, choose New > Class instead of File (this creates a Java class). Then put your Java code in this class. You can make the individual tests show up by either using the JUnit annotations or by using the "test" prefix on method names.
Then, make sure you rerun your JUNIT configuration (right click on the project and Run As Junit Test) after a rebuild.