Leads CA1822 to a bad design for modern development when it comes to unit testing?

456 views Asked by At

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?

1

There are 1 answers

0
Nicole Calinoiu On

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.