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.

Advertisement