I had never needed to unit test a private static class method in C# before, but it turns out that Microsoft created a special object type to handle just such a case.
To test the private static method DetermineFilename (that takes filePath as a string parameter and returns a string) in the FileManager class, do the following:
1 2 3 4 |
[sourcecode language="csharp"] PrivateType privateFileManagerObject = new PrivateType(typeof(FileManager)); string filename = (string)privateFileManagerObject.InvokeStatic("DetermineFilename", filePath); [/sourcecode] |
Thanks to Venkat for posting this solution on his web site here:
http://venkatcsharpinterview.blogspot.com/2011/07/unit-testing-private-static-method-in-c.html