InternalsVisibleTo

nUnit integration is made so much better with the InternalsVisibleTo attribute. Declare this in the assemblyInfo of the class you want to write tests for and specify the nunit dll that you want to be able to acccess the internals. [assembly:InternalsVisibleTo(“nunit.xml.whatever”)]

Why does this help?

Probably the best way to illustrate this is with an example. I have a class in an assembly which takes an object model, converts it to XML and then passes it into a webservice. My unit tests want to confirm that the serialization always work, not the webservice. My interface does not expose the XML at any point.

However with this attribute I can now expose the XML via an internal property, and pick it up as a test.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s