为 Eclipse 中现有类中的新方法生成 JUnit 存根
这个问题与 如何在中创建 JUnit 存根方法密切相关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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你已经修改了。
you've modified.
我的解决方案。
我只是通过标准的“创建 JUnit 测试用例”
选择要测试的文件。 ->新 Junit 测试用例
完成创建测试用例的正常过程,但仅选择那些您想要新存根的测试用例。
该文件是使用存根创建的,我现在将其复制到现有的测试用例文件中。
删除新创建的测试文件类。
当您手动创建它们时,这不是最有效的,但比“厚指法”更快。
大卫
My solution.
I simply go through the standard 'create JUnit test case'
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 会警告您方法“NewMethod”不存在。您只需选择“快速修复”(我不确定是 Ctrl-1 或 Ctrl-2)来创建类中缺少的方法。
The usual working cycle with unit tests is to create the test case first
At that point Eclipse will give you a warning that the method "NewMethod" does not exist. Than you simply select a "Quick Fix" (Ctrl-1 or Ctrl-2 i'm not sure) to create the missing method in the class.