Search code examples
c#unit-testingmstest.net-standard

How to test a PrivateObject in a .net standard test project?


I am following this tutorial, https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-mstest

but I don't have the type PrivateObject available, so I am wondering if it would be possible to test private objects with a .net standard 2.0 project.


Solution

  • Private objects are accessible only within the body of the class, so in order to test them you must do one of the following:

    1. make private objects public or
    2. implement public methods which will interact with these private objects