在单元测试中运行所有 stylecop 规则
无论如何,是否可以从单元测试运行所有 StyleCop 规则(相当于重新扫描所有规则)并根据警告进行断言?
提前致谢!
/碧玉
Is there anyway to run all StyleCop rules from a unit test (equivalent to rescan all) and assert based on warnings?
Thanks in advance!
/Jasper
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从技术上讲,您可以做到这一点,但这是使用 StyleCop 的非常(!)不寻常的方式。
首先,您应该学习如何从代码中运行 StyleCop。此讨论包含一些有助于实现此目的的示例:http://stylecop.codeplex.com/discussions/220546< /a>.
然后,您将能够创建单元测试,该测试将枚举并检查指定位置中的所有源文件。这里不好的部分是您需要以某种方式指定这个位置,并且单元测试将使用源代码而不是编译后的程序集(这是相当不典型的)。
但无论如何,我建议重新考虑你的方法。实际上并不需要将 StyleCop 错误视为编译错误。您可以在构建服务器上执行分析并以您喜欢的任何方式共享结果(单元测试也是如此)——一切都在您手中!
Technically, you can do it, but it is very (!) unusual way of using StyleCop.
First, you should learn how to run StyleCop from the code. This discussion contains some examples that can help implementing this: http://stylecop.codeplex.com/discussions/220546.
Then, you will be able to create unit-test that will enumerate and check all source files in specified location. The bad part here is that you will need to specify this location somehow, and unit-test will work with source codes instead of compiled assembly (which is rather untypical).
But anyway, I would recommend reconsidering your approach. It is not really required to consider StyleCop error as compilation errors. You could perform analysis on build-server and share the results in any way you like (the same thing about unit-tests) - everything in your hands!
我只是将它包含在我的构建过程中,如果有警告(通过 nant 或 ant 返回代码或类似的东西),则将构建视为失败。您可以将这些工具配置为仅发出您想要的警告。
无论如何,为什么在单元测试中需要它?
I'd just include it in my build-process and treat a build as failed if there're warnings (via a nant or ant return code or something similar). You can configure these tools to only spit out the warnings you want.
Why do you need it in a Unit-Test anyway?