This question is in its advanced years, but I thought I'd share my way of doing this.
Basically, I have all my unit test classes in the assembly they're testing in a 'UnitTest' namespace below the 'default' for that assembly - each test file is wrapped in a:
#if DEBUG
...test code...
#endif
block, and all of that means that a) it's not being distributed in a release and b) I can use internal
/Friend
level declarations without hoop jumping.
The other thing this offers, more pertinent to this question, is the use of partial
classes, which can be used to create a proxy for testing private methods, so for example to test something like a private method which returns an integer value:
public partial class TheClassBeingTested
{
private int TheMethodToBeTested() { return -1; }
}
in the main classes of the assembly, and the test class:
#if DEBUG
using NUnit.Framework;
public partial class TheClassBeingTested
{
internal int NUnit_TheMethodToBeTested()
{
return TheMethodToBeTested();
}
}
[TestFixture]
public class ClassTests
{
[Test]
public void TestMethod()
{
var tc = new TheClassBeingTested();
Assert.That(tc.NUnit_TheMethodToBeTested(), Is.EqualTo(-1));
}
}
#endif
Obviously, you need to ensure that you don't use this method while developing, though a Release build will soon indicate an inadvertent call to it if you do.