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 surprise, the required classes PrivateObject and PrivateType are not part of the .NET Core test framework. You can find an issue on that opened on GitHub: https://github.com/Microsoft/testfx/issues/366.

The not-so-good news on this is, that Microsoft decided not to take this feature back into the .NET Core test framework. The good news is, that the source of the required classes PrivateObject and PrivateType is published on GitHub.

You can either download a .zip containing one file with both classes from here: https://github.com/microsoft/testfx/files/4132970/PrivateObjectPrivateType.zip (I suggest to split this file into two, following one of my preferred development guidelines ‘one-type-per-file’). Or you can download them from the Microsoft TestFramework https://github.com/microsoft/testfx/tree/664ac7c2ac9dbfbee9d2a0ef560cfd72449dfe34/src/TestFramework/Extension.Desktop.

publicize.exe is still available when installing VS 2019, but I assume it will not generate the desired types for .NET Core assemblies, as the required base classes are missing (didn’t tested it; see Use Publicize.exe to Create Private Accessors for Visual Studio 2012+).

Links

GitHub issue “PrivateObject and PrivateType are not available for a project targeting netcorapp2.0 #366”

GitHub Source of PrivateObject and PrivateType

GitHub download .zip: as a single file

Home-made Private Accessor for Visual Studio 2012+

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

Leave a Comment

Please note that every comment requires the admin's approval before it will be published.

Any comment containing spam like "... great topic. Feel free to visit my web page ..." will be deleted. So please do not waste your and our time by leaving such comments.

We respect your privacy. When you leave a comment, your IP address will not be recorded by WordPress.