As per this answer to Unit testing private methods in C# I am using a PrivateObject to unit test private methods. This generally works really well and is quite easy to use, however it doesn't appear to work if the method is Shared
or Static
.
I don't really want to make the method public (otherwise I wouldn't even be bothering with PrivateObjects but I'm failing to see another way.
Example vb methods in class being tested:
Private Sub SampleInstanceMethod(arg as Object)
'Do something
End Sub
Private Shared Sub SampleSharedMethod(arg as Object)
'Do something
End Sub
Unit test code
Dim fooBarPO = New PrivateObject(GetType(FooBar))
fooBarPO.Invoke("SampleInstanceMethod", {arg1}) ' Works
fooBarPO.Invoke("SampleSharedMethod", {arg1}) ' Doesn't work
Interested in answers in either C# or VB