Rob Smyth

Thursday, 6 March 2008

Unit Testing Internal C# Classes

I like to keep my production code and my unit testing code in separate assemblies. A downside of this is has been that all classes must be public but I have now found that C# does support 'friend' assemblies via an AssemblyInfo.cs attribute:
[assembly: InternalsVisibleTo("UnitTests")]
I have not used this attribute yet, but I like the idea of making classes as internal. It makes the intent (usage scope) self evident. I wonder if it will help detect orphaned code?

3 comments:

Kenneth Xu said...

Works great, Thank you!

Anonymous said...

Rob,

This was a lifesvaer. Great find!

Asher said...

Perfect.