我们应该在UnitTest程序集上使用FxCop吗?

时间:2023-02-01 20:03:13

We use FxCop for all of our projects. For our UnitTests I am not sure it is worth it. We end up with many suppresses:

我们将FxCop用于所有项目。对于我们的UnitTests,我不确定它是否值得。我们最终得到了许多抑制:

[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = SuppressJustifications.CA1822MethodIsUsedExternallyAsNonStatic)]
[SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", MessageId = "Cantaloupe.Seed.Security.RijndaelEncryption", Justification = SuppressJustifications.CA1806MethodIsCalledForExceptionThrowingTest)]

What are people's thoughts on FxCop on Unit test code?

人们对单元测试代码的FxCop有什么看法?

4 个解决方案

#1


When I teach our unit test / TDD class, I usually tell people to write test code following the same principles as they would when writing prober production code. However, I acknowledge that some of the FxCop rules may generate too much noise.

当我教我们的单元测试/ TDD课程时,我通常会告诉人们按照与编写探针生成代码时相同的原则编写测试代码。但是,我承认一些FxCop规则可能会产生太多噪音。

Couldn't you use a suitable subset of the FxCop rules for the test code?

难道你不能为测试代码使用合适的FxCop规则子集吗?

#2


not worth the effort; FxCop is for production coding standards, not internal test code

不值得努力; FxCop用于生产编码标准,而不是内部测试代码

(however, it doesn't hurt to give it a run-through and a once-over every now and then, in case it tells you something useful...)

(然而,如果它告诉你一些有用的东西,那么偶尔给它一个贯穿并且一次又一次没有伤害...)

#3


Yes but you don't have to be a maniac about it. You're tests are your maintenance coder's best friend. If your tests aren't easy to read your maintenance coder will have a hard time of things. I think it helps encourage better habits, unit test code does not have a permissive license to be sloppy.

是的,但你不必是一个疯子。你的测试是你的维护编码员最好的朋友。如果您的测试不容易阅读,您的维护编码器将会遇到困难。我认为这有助于鼓励更好的习惯,单元测试代码没有宽松的许可证。

#4


GO ahead if you have time on your hands. Its not a bad idea to make the cop take a look at all your code.

如果你有时间,请继续前进。让警察看看你的所有代码并不是一个坏主意。

#1


When I teach our unit test / TDD class, I usually tell people to write test code following the same principles as they would when writing prober production code. However, I acknowledge that some of the FxCop rules may generate too much noise.

当我教我们的单元测试/ TDD课程时,我通常会告诉人们按照与编写探针生成代码时相同的原则编写测试代码。但是,我承认一些FxCop规则可能会产生太多噪音。

Couldn't you use a suitable subset of the FxCop rules for the test code?

难道你不能为测试代码使用合适的FxCop规则子集吗?

#2


not worth the effort; FxCop is for production coding standards, not internal test code

不值得努力; FxCop用于生产编码标准,而不是内部测试代码

(however, it doesn't hurt to give it a run-through and a once-over every now and then, in case it tells you something useful...)

(然而,如果它告诉你一些有用的东西,那么偶尔给它一个贯穿并且一次又一次没有伤害...)

#3


Yes but you don't have to be a maniac about it. You're tests are your maintenance coder's best friend. If your tests aren't easy to read your maintenance coder will have a hard time of things. I think it helps encourage better habits, unit test code does not have a permissive license to be sloppy.

是的,但你不必是一个疯子。你的测试是你的维护编码员最好的朋友。如果您的测试不容易阅读,您的维护编码器将会遇到困难。我认为这有助于鼓励更好的习惯,单元测试代码没有宽松的许可证。

#4


GO ahead if you have time on your hands. Its not a bad idea to make the cop take a look at all your code.

如果你有时间,请继续前进。让警察看看你的所有代码并不是一个坏主意。