用于保持单元测试正确组织和命名的工具
我一直在努力清理项目单元和集成测试的命名和组织约定。 我们使用 C#、NUnit、Visual Studio 和 Resharper。
看起来,如果单元测试组织有一个最佳实践的话,那就是测试类和命名空间的布局和命名应该反映被测代码的布局和命名。 因此,文件结构也将被复制。
如果有一个可以自动强制执行并帮助重构代码以符合这些约定的工具不是很好吗? 有这样的工具吗?
例如,Resharper 很容易识别出 OrderTest 是 Order 类的测试装置。 然后,它可以确保 Order 类存在并且位于同一命名空间中。 如果 Order 类进行了重构并重命名,则 OrderTest 类也应该重命名。
I have been trying to clean up the naming and organisation conventions of our projects' unit and integration tests. We are using C#, NUnit, Visual Studio and Resharper.
It seems that if there is one best practice for unit test organisation it is that the layout and naming of the test classes and namespaces should mirror those of the code under test. As a consequence the file structure will also be replicated.
Wouldn't it be nice to have a tool that could automatically enforce and help refactor code to conform to these conventions? Does a tool like this exist?
For example, it would be simple for Resharper to recognise that OrderTest is a test fixture for the Order class. It could then ensure that the Order class exists and that it is in the same namespace. If the Order class underwent refactoring and was renamed, the OrderTest class should also be renamed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我也经常想要这样。 我查看了 Resharper bug tracker,发现了这个问题的增强请求。 计划发布 Resharper 5.0。 以下是其描述: http://www.jetbrains.net/jira/browse/RSRP -64050。
至于单元测试的命名和组织,标准正在发生很大变化,尤其是一些突然出现的 bdd 样式。 这里是一篇关于该命名风格的好文章。 我认为工具最好让团队适应并创建自己的标准。 有了集体代码所有权,一段时间后就应该只有一个标准。
I have often wanted that too. I looked at the Resharper bug tracker and found the enhancement request of this issue. It is scheduled for Resharper 5.0. Here is its description: http://www.jetbrains.net/jira/browse/RSRP-64050.
As for the naming and organization of unit tests, standards are changing quite a bit, especially with some of the bdd styles that are popping up. Here is a good post on that naming style. I think it's best for tools to just let a team adapt and create its own standards. With collective code ownership, there should be just one standard after a while.
我们目前有Test01、Test02、Test03等...这就像海盗裤子里的方向盘。
我更喜欢并且正在改用这种命名方式:行为驱动开发:尽可能人性化
Ours are currently Test01, Test02, Test03, etc... It's like a steering wheel in a pirate's pants.
I much prefer, and am switching to, this style of naming:Behavior Driven Development: As Human As Possible
实际上,ReSharper 4.5 具有命名样式,如果您不遵循您设置的命名约定,它会警告您。 几天前我在博客上谈到了这一点。
如果您有兴趣,请点击此链接:
http://vkreynin.wordpress .com/2009/04/09/resharper-45-complains-about-my-private-fields/。
Actually ReSharper 4.5 has naming Styles that will warn you if you don't follow naming conventions you set. Few days ago I blogged about this.
If you are interested, follow this link:
http://vkreynin.wordpress.com/2009/04/09/resharper-45-complains-about-my-private-fields/.