为 JUnit 测试激活哪些 PMD 规则?
我正在将 PMD 设置为我们团队中的工具,以支持我们编写更好的代码。基本上我正在构建 Ant 脚本 并尝试设置一些规则供每个人使用。
但现在我遇到了这个问题:
当我编写 JUnit 测试 我不想使用与我相同的规则适用于我们的主要源代码。我不太关心 字符串规则 (如字符串重复或奇怪的实例化) junit 测试。
我的问题是:
- 这是我这边的错误吗?我应该开始编写更好的 JUnit 测试吗?
- 我是否应该提供第二组规则来禁用某些字符串/设计/终结器规则?
I'm in the middle of setting up PMD as a tool in our team to support us writing better code. Basically I'm building Ant scripts and try to set up some rules for everyone to use.
But right now I hit this problem:
When I write JUnit tests I don't want to use the same rules I apply on our main source code. I don't care that much about String rules (like string dupliates or weird instantiations) in the junit tests.
My questions is:
- Is that a fault on my side and should I start writing better JUnit tests?
- Should I provide a 2nd set of rules that disables some of the string/design/finalizers rules?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第二个选项 - 我根本不针对我的测试运行 PMD。我可以并且 PMD 提供了一些 JUnit 特定规则。不过,我肯定会针对测试代码使用单独的规则集。我期望更多的字符串文字和指定的一些内容,而不是使用条件/循环。毕竟,我不想重复我正在尝试测试的代码。
The second option - I don't run PMD against my tests at all. I could and PMD provides some JUnit specific rules. I would definitely use a separate ruleset against the test code though. I expect more String literals and some thing specified instead of using conditionals/loops. After all, I don't want to duplicate the code I am trying to test.
有两件事。为什么要尝试制定规则而不使用现有规则? (特殊要求?)。其次,当然单元测试也应该具有良好的质量。您的单元测试测试您的生产代码,因此它们不应该至少具有与您的生产代码相同的质量吗?
Two things. Why are you trying to set up rules why not using the existing rules? (Special requirements?). And second yes of course Unit tests should have a good quality as well. Your Unit test test you production code so shouldn't they have at least the same quality as your production code?