A common requirement for unit test framework is the ability to test internal types.
That's easy! use InternalsVisibleToAttribute
With .Net 2.0 and up, this is a fairly easy task thanks to the InternalsVisibleToAttribute: add it to the product assembly to give 'visibility rights' to the test assembly.
// in assembly Foointernal class Foo {}// giving visibility rights to the Foo.Tests assembly[assembly:InternalsVisibleTo("Foo.Tests")]
On the test assembly side, this works because unit test are 'closed' methods which do not expose any internal types.
[Test]public void FooTest() { Foo foo = new Foo(); // we're using the internal type Foo // but it's hidden in the unit test}
What about parameterized tests? Make them internal as well
If one of the parameters of the test is internal, the test method will have to be internal as well in order to compile:
[PexTest]internal void FooTest(Foo foo) { ... }
Not pretty but still gets the job done. Pex will generate public unit test methods that invoke the internal parameterized test method, and we'll be happy:
[Test]public void FooTest_12345() { this.FooTest(null);}
What about MbUnit RowTest?
This issue was never faced by MbUnit RowTest because it only accepts intrinsic types such as int, long, etc... Those types are obviously public :)
Page rendered at Saturday, August 09, 2008 4:26:49 AM UTC
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.