chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Hi there,

I want to test a private static method and I simply do not find a way to do it. :(

The setup is an extension class which implements a couple of extension methods and these extension methods use private (to the extension class) methods to accomplish there jobs. And I want to test them. However some of which are generic and return a value. And I want to test the returned value.
Just to show the general idea:
public static class Extensions
{
   public static DoSomting (this foo, int x)
   {
        DoSomethingElse<int> (x);
        return x*2;
   }

   // this method shall be tested and the return value shall be checked
   private static T DoSomethingElse<T> (T x)
   {
       if(typeof(t)==typeof(int))
          return x*2;
       return default(T)
   }
}


I have searched the documentation and was not able to find help. :(

Could anyone give me a hint?

Thank's in advance.
mph
asked by mph (6k points)

4 Answers

0 votes
Hi,

I am not quite sure i understand what you are trying to accomplish here :?

Are you trying to invoke DoSomethingElse?
Are you trying to invoke DoSomting and fake DoSomethingElse?

_________________
Yonatan
Typemock Support
answered by yonatan (1.6k points)
0 votes
My appologies if did not make myself clear here. I want to invoke DoSomethingElse first.
Peter
answered by mph (6k points)
0 votes
Hi Peter,

Invoking private generic methods is not currently supported in our API...
If all you want to do is invoke that private method (without faking it), please consider simply using reflection. see this Stack Overflow answer:

http://stackoverflow.com/questions/2325 ... ric-method

Another possibility - you may make that method Internal instead of private. Sometimes it is forgivable...

Aside from the technical issue here, without me knowing what it is you are actually testing, I do recommend focusing your tests on the public methods of your classes, using them to invoke the private methods in the process.
That way the tests are less dependent on the implementation details of your product.

Good luck,
_________________
Yonatan
Typemock Support
answered by yonatan (1.6k points)
0 votes
Thank you for hint!

And also for the advise. I will think my testing strategy over.

Peter
answered by mph (6k points)
...