Here's something that has worked for us with great success.
Mark the methods that you want to isolate and test but don't want
public with the protected internal virutal access modifiers, and
include the
[assembly: InternalsVisibleTo("TestAssembly")]
attribute in the AssemblyInfo.cs of the project containing the class
you want to test.
This way your assembly's protected internal methods are completely
testable and mockable but still not part of the public interface.
Hope this helps!
On Apr 6, 6:28 am, Stefan Steinegger <[email protected]> wrote:
> I think you can do this:
>
> var mockery = new MockRepository();
> var cnn = mockery.PartialMock<Connection>(HOST, PORT,
> CONNECTIONTIMEOUT, READTIMEOUT);
>
> // put mock into replay mode
> cnn.Replay();
>
> // and now use "normal" AAA
> cnn.Stub(x => x.Foo());
> cnn.AssertWasCalled(x => x.Bar());
>
> Doesn't this work?
>
> On 4 Apr., 05:33, Tim Barcz <[email protected]> wrote:
>
>
>
> > this is something I've done before and am open to it. However I just want
> > to say I only care about the "private method" to the extent that I can run
> > through some various scenarios. In fact, in the beginning the two methods
> > were just one. The second method was created to isolate the code that I
> > would want to mock, simulating various scenarios.
>
> > Tim
>
> > On Fri, Apr 3, 2009 at 9:38 PM, Shane Courtrille
> > <[email protected]>wrote:
>
> > > When you want to make a private/protected method testable my preference is
> > > to
>
> > > 1. Rethink if you really want to do this. It smells strongly when you're
> > > that worried about internals. Maybe you're missing another class
> > > somewhere?
> > > 2. If it passes the smell test. Do this..
>
> > > public MyClass
> > > {
> > > private int _ValueIWantToSee;
>
> > > private bool MethodIWantToTest() {}
> > > }
>
> > > Make your privates protected.
>
> > > Wherever you are storing all your tests (which shouldn't be included in
> > > your release) create the following class
>
> > > public MyClassWhichICanTestWith
> > > {
> > > public ValueIWantToSee { get { return _ValueIWantToSee; }
>
> > > public bool AccessToMethodIWantToTest() { return
> > > base.MethodIWantToTest(); }
>
> > > }
>
> > > I should note I actually don't use PartialMocks (since I very rarely use
> > > inheritance. Composition is your friend) myself so I use this technique
> > > to
> > > access important but private stuff in tests.
>
> > > On Fri, Apr 3, 2009 at 8:32 PM, Tim Barcz <[email protected]> wrote:
>
> > >> ie. a hand-rolled stub.
>
> > >> am I understanding you correctly?
>
> > >> On Fri, Apr 3, 2009 at 9:27 PM, Shane Courtrille <
> > >> [email protected]> wrote:
>
> > >>> Actually a better option is to make the method protected and create a
> > >>> test class that inherits. You can make things accessable however you
> > >>> want
> > >>> from that class. This way the public stuff is only available within
> > >>> your
> > >>> tests.
>
> > >>> On Fri, Apr 3, 2009 at 6:18 PM, Tim Barcz <[email protected]> wrote:
>
> > >>>> That was my rationale as well. While there are public methods, in our
> > >>>> application the interface does not contain these method and therefore
> > >>>> are
> > >>>> not available.
>
> > >>>> Tim
>
> > >>>> On Fri, Apr 3, 2009 at 7:03 PM, mike <[email protected]> wrote:
>
> > >>>>> I consider making methods virtual & public in a class fine because I
> > >>>>> access them only through interfaces.- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/RhinoMocks?hl=en
-~----------~----~----~----~------~----~------~--~---