Testing Nonpublic Members

Sometimes you need to test classes and members that are not public but are internal to a project, such as during system testing, where you need to interact with UI elements directly. To have access to internal members, you must allow the test project access to the internal members of the main project. You do this by placing an InternalsVisibleTo attribute into the AssemblyInfo class of the main project, as shown:

[assembly: InternalsVisibleTo("WPUnleashed.Tests")]

The InternalsVisibleTo attribute accepts a single parameter, which is the name of the assembly. If the test project has a strong name, the full name of the assembly must be used, including its public key token.

Examples of the InternalsVisibleTo attribute are ...

Get Windows® Phone 8 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.