Private Accessor for .NET Core Assemblies

As I do not share the opinion that testing of private methods is an anti-pattern (to me, it is essential to implement complete button-up tests), I tried to implement a private accessor based on my post Home-made Private Accessor for Visual Studio 2012+ for a .NET Core project. To my …

Use Publicize.exe to Create Private Accessors for Visual Studio 2012+

Preface Starting with Visual Studio 2012, private accessors cannot be created any more by the IDE. The post Home-made Private Accessor for Visual Studio 2012+ presents an approach on how to create private accessors using the class Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject. Axel Mayer noted in the MSDN forums post How to create private …

Home-made Private Accessor for Visual Studio 2012+

Why Home-made? Short answer: Starting with Visual Studio 2012, private accessors cannot be created any more by the IDE. It seems that this does not bother too many people. The ‘Bring Back Private Accessor’ suggestion on UserVoice has not found any supporters right now. Nevertheless, I still need access to …

Unit-Testing of Private Async Methods with Visual Studio

Description Given there is the need to unit-test a private async method. The class to be tested might look like this: public ClassWithPrivateAsyncMethod { // Some stuff private async Task PrivateMethodAsync ( string input ) { // Call some async framework method var result = await SomeFrameworkMethodAsync(input); // do something …

Handling of Out-Parameters with .NET Reflection

Since Microsoft decided to remove the creation of private accessors for unit tests in Visual Studio 2012, one have to get familiar with the usage of Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject. This class offers an easy way to call methods, independent from their visibility, via reflection. The method is PrivateObject.Invoke. This method saves you …

Limitations of Private Accessors and Generic Methods (JIT Compiler Encountered an Internal Limitation)

Private accessors are really helpful for extensive unit testing. But they do have their limitations. I wrote a generic protected method having a declaration like this: protected ReturnType MyMethod<T>(OneClass, DateTime, DateTime, Func<OtherClass, T>, out List<T>); Calling this method via an accessor in my unit test, I ran into an exception …

Accessing Non-Public Member of Abstract Base Classes in Unit Tests

Given you have an abstract base class with non-public member, and a derived class with other non-public member too. Now you want to unit-test some of the non-public member (methods) of the derived class. Prior the call of the method of the derived class, you need to set some non-public …

Silverlight Unit Test Headwords

At the time of writing, creating unit tests for Silverlight is not as smooth and easy as it is for .NET assemblies. My experiences base on the Silverlight toolkit published on Codeplex silverlight.codeplex.com. You cannot access private or protected methods or properties. So use the #if DEBUG to make these …