ASP.NET Unit Tests and Private Accessors

The code that is generated for testing an ASP.NET application uses private accessors even when everything that you are testing is public.

Why does the generated code use private accessors? Because Web code does not have a predictable assembly name to which you can bind a process at run time and deployment time. At run time, the test assembly, which contains your unit tests, must be able to bind to an assembly that contains the code you want to test. This binding lets your unit tests run on the methods in that assembly.

To make run-time binding possible, the generation of the unit test also creates a type, by using reflection, in the ASP.NET context. This newly created type is located in an assembly in the app domain of your ASP.NET application. After this run-time binding is achieved, reflection must be used to access it, and this reflection is performed by the private accessor object.

See Also

Tasks

How to: Debug while Running a Test in an ASP.NET Solution

Concepts

Unit Tests for Internal, Private, and Friend Methods

Overview of ASP.NET Unit Tests