First off, you made the comment that ClassX.MethodX() instanties
ClassY and calls a method on it.  With MethodX() being in control of
the instantiation of ClassY, you won't be able to stub out the ClassY
implementation, which will make testing more difficult.  I would make
ClassY a ctor dependency on ClassX so you can use injection.

Now as to your unit test, what do you want to test?  Do you want to
make sure that any call to MethodX() will call ClassY.MethodY()?  This
is doable once you have make the changes noted above so you can mock
out ClassY.  However, this type of test is a little more brittle
because it's really testing the implementation of MethodX().  If
sometime later you find a better way for MethodX() to work and you
re-factor it so you no longer use ClassY(), but still produce the same
result, your unit test that expects ClassY to be called will be
broken.

I think a better thing is to simply check and make sure that, given a
specifc input, MethodX will produce a specific output.  This type of
test doesn't get into the details of how MethodX works, but simply
that it's producing correct results based on it's input.  For this,
you stub out any dependancies that MethodX() needs.  You set those
dependancies up to return known responses.  Then you feed data into
MethodX(), get the return value and validate it for correctness.

---
Patrick Steele
http://weblogs.asp.net/psteele


On Thu, Mar 4, 2010 at 8:11 PM, gsogol <[email protected]> wrote:
> I have ClassX that has MethodX. MethodX takes in DtoX. MethodX in
> return instantiates another class, ClassY which calls MethodY which in
> return calls db. I obviously do not want to call the db and hence the
> isolation frameworkn but what is the best way to test this out?
>
> I currently have the following but failing to see what I'm really
> testing here and what what the point is:
>
> ClassX stub = MockRepository.GenerateStub<ClassX>();
> stub.Stub(x => x.MethodX(Arg<DtoX>.Is.Anything)).Return(expected);
> DtoX request = new DtoX(null);
> DtoY response = stub.MethodX(request);
> // asserts
>
> stub.AssertWasCalled(x => x.MethodX(request));

-- 
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.

Reply via email to