Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

ASP.NET Unit Tests and Private Accessors

Visual Studio 2005

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

Community Additions

ADD
Show:
© 2015 Microsoft