如何在 Eclipse 中创建存根 Junit 测试?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1894298/
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
How can I create stub Junit tests in Eclipse?
提问by peter.murray.rust
Is there a simple way of creating stubs for Junit4 tests in Eclipse (Galileo)?
是否有一种简单的方法可以在 Eclipse (Galileo) 中为 Junit4 测试创建存根?
回答by Michael Patterson
In the Package Explorerview, right-click on the file that you would like to create a JUnit test for. In the opened context menu, select New-> Other.... In the Select a wizarddialog, select Java-> JUnit-> JUnit Test Case.
在Package Explorer视图中,右键单击要为其创建 JUnit 测试的文件。在打开的上下文菜单中,选择New-> Other...。在选择向导对话框中,选择Java-> JUnit-> JUnit 测试用例。
Then a dialog opens. In case you have a default Mavenor Gradleproject, you will probably have to change the default Source folderfrom the provided ${PROJECT_NAME}/src/main/java
to ${PROJECT_NAME}/src/test/java
. If you click Next, the dialog allows you to check which methods to automatically create stubs for.
然后会打开一个对话框。如果您有一个默认的Maven或Gradle项目,您可能需要将默认的Source 文件夹从提供${PROJECT_NAME}/src/main/java
的${PROJECT_NAME}/src/test/java
. 如果单击Next,该对话框允许您检查要自动为其创建存根的方法。
回答by fastcodejava
You might also look into Fast Code Eclipse Plugin. Once you configure you can generate junit/testng test by selecting the class or any method. Also gives you way to navigate from a method to all the tests.
您还可以查看Fast Code Eclipse Plugin。配置完成后,您可以通过选择类或任何方法来生成 junit/testng 测试。还提供了从方法导航到所有测试的方法。