是否可以将 JUnit 测试用例与 Eclipe 中测试的类同步?
我知道可以使用 JUnit 中的向导创建 TestCase 或 TestSuite,但是在测试下的类被修改后(例如方法签名修改或新添加的方法),如何同步代码。 我希望我的测试用例能够在我的测试用例中同步(删除或添加)那些更改的方法/参数/方法签名。
我尝试在Google上搜索没有结果,也许有一个eclipse插件可以实现这一点?
I know it is possible to create a TestCase or TestSuite with the wizard within JUnit, but how does one sync the code after the class under the test has been modified, such as method signature modification or newly added methods. I would like my TestCases to be able to sync up (remove or add) those changed methods/parameters/method signatures within my TestCases.
I tried searching on Google to no avail, maybe there is an eclipse plugin for that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如前面提到的,只要您使用 Eclipse 工具进行重构,而不是通过手动重命名等方式进行重构,重命名或移动等重构就会自动反映在测试用例中。
对于新方法,不可能自动生成测试。 当然,自动生成的代码有一些例外,您可以在其中控制生成,也可以生成测试用例,但对于“正常”手动代码,您可以做的最好的事情就是提供存根(空方法),这有什么用在那里面?
更好的方法是使用诸如 Cobertura 或 艾玛 ,它恰好有一个不错的 Eclipse 插件,它允许您在源代码中查看代码是什么被测试覆盖,哪些没有。 这就是您需要更多测试的地方的报告。
As has been mentioned before, refactorings such as renames or moves will be automatically reflected in the test cases as long as you refactor using the Eclipse tooling and not by manually renaming for example.
As for new methods, it's impossible to generate tests automatically. Of course there are some exceptions for auto-generated code where you control the generation and where you could generate test cases as well but for "normal" manual code the best you could do was to provide stubs (empty methods), and what's the use in that?
A better approach is to track code coverage using a tool such as Cobertura or Emma, which happens to have a nice Eclipse plugin that allows you to see, inside your source code, what code is being covered by tests and which isn't. This then is your report of where you need more testing.
与生产代码的结构具有 1-1 关系的测试是测试气味。 最好将测试编写为系统行为的规范(~每个行为一个测试),而不是根据生产代码生成测试(~每个方法一个测试)。
引用自 http://blog.daveastels.com/files/BDD_Intro.pdf
Tests which have a 1-1 relationship with the structure of the production code are a test smell. It's much better for the tests to be written as a specification of the system's behaviour (~one test per behaviour), instead of having tests generated based on the production code (~one test per method).
Quoted from http://blog.daveastels.com/files/BDD_Intro.pdf
如果您使用自动重构更改方法签名,则测试用例以及调用该方法的所有其他代码将自动更新。
对于新添加的方法,我不知道如何自动更新测试类。
If you change method signatures using the automated refactoring, then the test cases - and all other code that calls the method - will be automatically updated.
For newly added methods, I don't know of a way to have the test class automatically updated.