在Eclipse中为现有类中的新方法生成JUnit存根 [英] Generating JUnit stubs for new methods in existing class in Eclipse
问题描述
此问题与如何创建JUnit有切线的相关性eclipse中的存根方法,但它并没有回答我的具体问题。
This question is tangentially related to How can I create JUnit stub methods in eclipse? but it doesn't answer my specific question.
假设你有一个现有的JUnit测试用例类,如果你添加一个方法目标类(或选择测试以前未测试的方法)有没有办法告诉Eclipse为现有TestCase中的新方法生成存根,而不创建新的测试用例类?
Assuming you have an existing JUnit test case class, if you add a method to the target class (or choose to test a previously untested method), is there a way to tell Eclipse to generate the stub for the "new" method(s) in the existing TestCase without creating a new test case class?
推荐答案
我的解决方案
我只是通过标准的创建JUnit测试用例'
I simply go through the standard 'create JUnit test case'
选择要测试的文件。 - >新的Junit测试用例
Select file to test. -> New Junit test case
在创建测试用例时,请查看正常的过程,但只能选择那些您想要的新存根。
Go through the normal process in creating the test case, but only select those that you want new stubs for.
该文件使用存根创建,我现在将其复制到现有的测试用例文件中。
删除新创建的测试文件类。
The file is created with the stubs, which I now copy into the existing test case file. Delete the newly created test file class.
当您手动创建它们时,它不是最有效率,而是比粗指法更快。
It's not the most efficient, but quicker than 'thick fingering' when you create them manually.
David
这篇关于在Eclipse中为现有类中的新方法生成JUnit存根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!