making internals visible to nunit only

147 views
Skip to first unread message

Costa-AEGISoft

unread,
Jul 20, 2010, 11:47:39 AM7/20/10
to NUnit-Discuss
hello,

being a great fan of nunit, i've been enhancing the architecture of my
test projects to remove code duplication as much as possible while
keeping my production code as private as i can.

I often reuse the setup of similar tests by letting them inherit from
a base class having the general context, and then have each fixture
add its variation. I also use the so called ObjectMother pattern to
extract common test setups.

eg: (pls don't mind the typos' --> it's just to give you a rough
idea ;-)

[Fixture]public abstract class AaaStyleSpec
{
[SetUp]public void SetUp()
{
Arrange();
Act();
}

protected virtual void Arrange(){}
protected virtual void Act(){}
}

[Fixture]public abstract class baseContextForTestA: AaaStyleSpec
{
protected SutType _sut;
public override Arrange() { <common context ... > }
public override Act() { _result = _sut.MethodToTest(); }

[Test]public void This_should_always_be_so() {...}
}

[Fixture]public class variation1OfTestA: baseContextForTestA
{
public override Arrange() { base.Arrange(); <+variation1>...}

[Test]public void This_should_only_be_so_in_case_of_variation_1()
{
//here i need access to the base._sut using Rhino.Mock
extensions
_sut.AssertWasCalled(x=>x.SomeSupportingMethod());
}
}

[Fixture]public class variation2OfTestA: baseContextForTestA
{
public override Arrange() { base.Arrange(); <+variation2>...}

[Test]public void This_should_only_be_so_in_case_of_variation_2()
{...}

}


now with this setup I often have to make Systems Under Test protected
in those public fixtures ( so i can access them in the subclasses)
--> eg if SutType is internal then because the fixtures are public, i
have to 'promote' it to being public.

I would like to make the TestFixtures internal, so that i can keep
them internal in the production assembly as well
--> but for that i need Nunit's publickey to make my
'InternalsVisibleTo("nunit.framework, publickey=???")'

For now I just make the SUTs public or i derive an interface that i
make public.
but that all pollutes my assembly's interface.

I searched the net for the public key or other solutions, but I
haven't found anything usefull...
--> so is it possible to release that public key or are there better
ways to keep my internals inside while keeping test code duplication
to a minimum ??

thx,
Olivier Costa
in...@AEGISoft.be


PS: if there's a better forum for this kind of question, pls redirect
me ;-)

Charlie Poole

unread,
Jul 20, 2010, 2:55:28 PM7/20/10
to nunit-...@googlegroups.com
Hi,

I'm not sure what the problem is with running these tests. I just
created an internal
test fixture as part of the NUnit tests and was able to run it
correctly. Since NUnit
accesses the tests via reflection, there should be no need for
InternalsVisibleTo
with regard to NUnit. Of course, you will have to make sure that the
internals of
your SUT are visible to your tests.

Naturally, there's no problem with publishing the NUnit public key and
I'll put that
on my todo list. It's accessible anyway since the source includes the key file.

Let me know if there's some wrinkle to your problem that I'm missing.

Charlie

> --
> You received this message because you are subscribed to the Google Groups "NUnit-Discuss" group.
> To post to this group, send email to nunit-...@googlegroups.com.
> To unsubscribe from this group, send email to nunit-discus...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nunit-discuss?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages