Java Mailing List Archive

http://www.gg3721.com/

Home » user.jmock »

Re: [jmock-user] Sharing/Reusing Expectations across tests.

Nat Pryce

2009-07-29

Replies: Find Java Web Hosting

Author LoginPost Reply
The other thing I'd do is split the class into smaller component
classes and exhaustively test those, and then have a coarser grained
test around the processor itself that just checks that it composes its
components correctly.

--Nat

2009/7/29 Nat Pryce <nat.pryce@(protected)>:
> 2009/7/29  <chris@(protected)>:
>> I only have one public method in which I want to assert that a bunch of
>> different things are happning inside it. I cant see a way of refactoring
>> it in a way that for each step of important behaviour in the process()
>> method can be asserted and tested without having to repeat/include all the
>> assertions before and after.
>
> It sounds like you're focusing the test on the wrong thing. I would
> not write a test for each "step" in the process method.  Rather I'd
> focus it on each feature of the object as far as the client is
> concerned, running (and testing) the entire process method from entry
> to exit in each test.
>
> You might have different tests for:
>
> * possible paths through the conditionals in the process method.
> * error cases: what happens when there is invalid input or dependencies fail
> * how the process method notifies listener A
> * how the process method notifies listener B
>
> For the listener tests, I would only attach the relevant listener at
> the start of that test.  That way, all other tests don't need to
> explicitly ignore it.  For example:
>
> @Test
> public void notifiesSheepListenerWhenSheepProcessed() {
>    final SheepListener sheepListener = context.mock(SheepListener.class);
>    processor.addSheepListener(sheepListener);
>
>    context.checking(new Expectations() {{
>        oneOf(sheepListener).sheepProcessed();
>
>        ... and expectations to make it process a sheep ...
>    }});
>
>
>    processor.process(); // maybe with arguments to make it process a sheep
> }
>
> --Nat
> --
> http://www.natpryce.com
>



--
http://www.natpryce.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


©2008 gg3721.com - Jax Systems, LLC, U.S.A.