PartialMock for AAA

38 views
Skip to first unread message

Tim Barcz

unread,
Jun 22, 2009, 10:12:44 PM6/22/09
to rhino-t...@googlegroups.com, Rhino Mocks
Anybody have an issue if I add in support for partial mocks in AAA syntax...?

Long run: would like to see record/replay made obsolete and the focus given to AAA entirely (RhinoMocks 4.0?)

Thoughts? Approvals? Concerns?

--
Tim Barcz
ASPInsider
http://timbarcz.devlicio.us
http://www.twitter.com/timbarcz

Mark

unread,
Jun 22, 2009, 10:38:26 PM6/22/09
to Rhino...@googlegroups.com

I’m +1 for concentrating on AAA – is so much easier to teach newbies (not that I’m an expert…)

Adam Tybor

unread,
Jun 23, 2009, 12:37:32 PM6/23/09
to Rhino.Mocks
+1
Add support for multimock as well, maybe just a couple generic type
overloads. its really handy for mocking wcf proxies and idsposable.

Mark wrote:
> I'm +1 for concentrating on AAA - is so much easier to teach newbies (not
> that I'm an expert.)

Chris Missal

unread,
Jun 23, 2009, 3:34:29 PM6/23/09
to Rhino...@googlegroups.com
I picked up AAA fairly easy and think it would be good to have.
--
Chris Missal
http://chrismissal.lostechies.com/

Kenneth Xu

unread,
Jun 27, 2009, 11:40:48 AM6/27/09
to Rhino...@googlegroups.com
+1. For all the developers with whom I have worked, including myself,
it took us a while to get used to record/reply. Then end up with
overly interactive test cases that fails whenever the implementation
changes. Only a few good ones eventually start to think when to stub
and when to mock and what to expect, but it took even longer than the
time taken understanding record/replay.

Kenneth Xu

unread,
Jun 28, 2009, 8:27:57 PM6/28/09
to Rhino...@googlegroups.com
Hi Tim,

After looking at the source code of Rhino.Mocks. I started using
PartialMock for AAA in my tests. It is working surprisingly well. See
the code below.

Cheers,
Kenneth

class Mockery : MockRepository
{
public static T GeneratePartialMock<T>(params object[]
argumentsForConstructor)
where T : class
{
var mockery = new MockRepository();
var mock = mockery.PartialMock<T>(argumentsForConstructor);
mockery.Replay(mock);
return mock;
}
}

[Test] public void
NewTaskForCallGetsNewTaskFromAbstractExecutorService()
{
Call<T> call = delegate
{
return TestData<T>.One;
};

var futureTask = Mockery.GeneratePartialMock<FutureTask<T>>(call);

ExpectExecuteCallAndRunTheRunnableInCurrentThread();
_executor.Expect(e => e.NewTaskFor(call)).Return(futureTask);

var f1 = _sut.Submit(call);
Assert.That(f1, Is.SameAs(futureTask));
var f2 = _sut.Poll();
Assert.That(f2, Is.SameAs(futureTask), "submit and take
must return same objects");
futureTask.AssertWasCalled(ft => ft.Done());
_executor.VerifyAllExpectations();
}

private void ExpectExecuteCallAndRunTheRunnableInCurrentThread()
{
_executor.Expect(e => e.Execute(Arg<IRunnable>.Is.NotNull))
.WhenCalled(r => ((IRunnable)r.Arguments[0]).Run());

Tim Barcz

unread,
Jun 28, 2009, 8:51:50 PM6/28/09
to Rhino...@googlegroups.com
Yep, that's what I've got basically added.  PartialMocks were very easy, I will get committed to trunk...but I don't have yet is StrictMultiMocks....those are proving more difficult.

Tim

Adam Tybor

unread,
Jul 6, 2009, 10:11:57 AM7/6/09
to Rhino.Mocks
Tim how far did you get with this... I am almost done with adding
Partials, MultiMock, and StrictMock.... Do we really need a strict
mock anymore?

The only major issue I had was with test case for the MultiMock that
was choking on the AssertExactlySingleExpectaton because calling the
method collectionBase.Clear() actually calls collectionBase.OnClearing
() and collectionBase.OnClearCompleted() which are protected virtual
and getting caught by the RhinoInterceptor. There is no easy solution
for ensuring that people are only doing a Single Expectation Assertion
in foo.AssertWasCalled(...).

I went down the rabbit hole of changing Action<T> to
Expression<Action<T>> which does not work when trying to assert
assignment from a property setter... maybe in .net 4.0 when we get
full expression tree support with the DLR will it work??

For now the work around in the MultiMock test was to simply call
baseCollection.VerifyAllExpectations() which seemed to do the trick.

I am just doing a little cleanup at this point, should I commit when I
am done or would you guys rather see a patch?

Adam

Tim Barcz

unread,
Jul 6, 2009, 10:25:39 AM7/6/09
to Rhino...@googlegroups.com
I say we bring forward strict mock....looking for feature parity with Record/Replay so it can go away.

Tim

Adam Tybor

unread,
Jul 7, 2009, 10:19:01 AM7/7/09
to Rhino.Mocks
I commited some stuff yesterday in trunk that i would like to be
reviewed. i am not crazy about all the generatxxx methods. I really
like the fluent Type marker pattern that is in rhino.testing.

Also why r partials strict mocks?

Adam

Shane Courtrille

unread,
Jul 7, 2009, 2:46:03 PM7/7/09
to Rhino...@googlegroups.com
Would love to know this as well.  It's kind of annoying.
Reply all
Reply to author
Forward
0 new messages