We use Code Analysis within a build server with the firm restriction that we cannot commit code if a Code Analysis rule breaks. CA1822 is enabled and therefore we have many, many static functions. Now we want to force unit tests with mocking and dependency injection. But with our many static functions it is not easy to mock some static function. Especially when a static function calls a static function. I'm thinking about disabling CA1822 to reduce the static functions because I'm aksing myself: Is CA1822 obsolete for development with a mocking fw and code injection? I read in many other questions, that performance is not the matter. So what for making a function static? In my opinion CA1822 lead to a bad design. Am I wrong?
Asked
Active
Viewed 397 times
1
-
What language / platform? Please tag accordingly. – Jonathon Reinhart Sep 05 '13 at 06:48
-
1Actually this question applies to every language having Code Analysis support and even for languages with similar tools and rules. In my case it is VB.net and C# – Jeremy Benks Sep 06 '13 at 05:32
1 Answers
2
CA1801 is the ReviewUnusedParameters rule. CA1822 is MarkMembersAsStatic, which is the one that I'm guessing is actually causing problems for you.
The good news is that neither of these rules fires for an implementation of an interface method, so you should have no problems with either rule if you start decoupling via interfaces in order to enable inversion of control and mock substitution for unit testing.

Nicole Calinoiu
- 20,843
- 2
- 44
- 49