locked
Apparent bug in VS2013: PrivateType.InvokeStatic RRS feed

  • Question

  • I've encountered what seems to be a bug in the PrivateType class. Specifically, it can't find private, static GENERIC methods. A tentative search on the internet seems to indicate that this has been an issue since VS2010. I'm hoping for official confirmation so I can stop searching.

    Toy example:

    class MyClass {
       private static bool Compare<T>( T a, T b ) { 
           return a.Equals(b); 
       }
    }
    
    ... test framework ...
    
    [TestMethod]
    public void TestStuff() {
       PrivateType pt = new PrivateType( typeof(MyClass) );
       Type t = typeof(int);
       bool result = (bool)pt.InvokeStatic("Compare", 
               new Type[] {t, t}, 
               new object[] {1, 3}, 
               new Type[] {t} 
       );
    
    }

    The attempt to invoke should throw a System.ArgumentException.  The example is a distilled version of what I'm currently running.  Only the method name has been changed and none of the surrounding code is included.

    Wednesday, November 11, 2015 3:58 PM

Answers

  • Hi curds01,

    Just to make this issue clearly, do you mean that you want to test a private method in your unit test project, am I right? 

    As far as I know, it changed some features from the VS2010.

    Like this blog:

    How to test Private methods using Visual Studio’s testing framework

    In the higher VS version, Testing private methods can be done using the PrivateObject class.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 13, 2015 5:23 AM