0

how to write unit test for private static method in c#? Is that good to have private static method?

private static <someReturnType> SomeMethodName(SomeParameters){}
f_puras
  • 2,521
  • 4
  • 33
  • 38
Rags
  • 3
  • 5
  • possible duplicate of [Unit testing private methods in C#](http://stackoverflow.com/questions/9122708/unit-testing-private-methods-in-c-sharp) – Old Fox Jul 15 '15 at 09:11
  • No, it's not. Regardless of the advisability of testing private methods (I tend to believe that they should be tested), the process used to test an object's methods does not work for static methods. – Auspex Nov 12 '15 at 13:08
  • Would love an actual answer to this question. It's strange the approach for testing private members doesn't work for static methods. – Extragorey Sep 28 '17 at 23:54

1 Answers1

0

The answer to this is don't test the implementation details of your class, test its behaviour or interactions. The fact that the method is static is irrelevant.

You unit test should validate that given some conditions, calling a public method results in some expected response or expected interaction with dependencies. How that response is generated or how the interactions happen in the class under test are not really important, what's important is the externally verifiable behaviour.

Sam Holder
  • 32,535
  • 13
  • 101
  • 181