Changing expectations

View: New views
6 Messages — Rating Filter:   Alert me  

Changing expectations

by ueland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Is there a way to change return values for expectations after they are set? I
want to do this for some tests where 99 % of the test methods use predefined
expectations set up from setUp(), but a few needs other return values.

Example:

void setUp() {
  expectation1 returns status1
  expectation2 returns status2
}

99 % of the tests use status1 and status2 to go green, but one test needs
expectation2 to return another status.

How can this be done without calling a setup method in all the tests? I have
tried to return an instance variable from the expectations, but that didn't
work. In JMock 1 the method reset() could be used to reset expectations. Have
not found a similar method in JMock 2.



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

    http://xircles.codehaus.org/manage_email


Re: Changing expectations

by Keith Sader :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

@Test public void someOtherTestWithDifferentSetup() {
   this.expectation1 = new Expectation() {{
      will().returnValue(foo); // I don't remember the exact syntax off-hand.
      ....
    }};
}

Would that work for you?


On Nov 26, 2007 6:36 AM, Harald Ueland <harald@...> wrote:

> Hi,
>
> Is there a way to change return values for expectations after they are set? I
> want to do this for some tests where 99 % of the test methods use predefined
> expectations set up from setUp(), but a few needs other return values.
>
> Example:
>
> void setUp() {
>   expectation1 returns status1
>   expectation2 returns status2
> }
>
> 99 % of the tests use status1 and status2 to go green, but one test needs
> expectation2 to return another status.
>
> How can this be done without calling a setup method in all the tests? I have
> tried to return an instance variable from the expectations, but that didn't
> work. In JMock 1 the method reset() could be used to reset expectations. Have
> not found a similar method in JMock 2.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>



--
Keith Sader
ksader@...
http://www.sader-family.org/roller/page/ksader

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

    http://xircles.codehaus.org/manage_email


Re: Changing expectations

by Nat Pryce :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 26/11/2007, Harald Ueland <harald@...> wrote:
> Is there a way to change return values for expectations after they are set?

No.

> I want to do this for some tests where 99 % of the test methods use predefined
> expectations set up from setUp(), but a few needs other return values.
>
> How can this be done without calling a setup method in all the tests?

It cannot.  That's because pulling the common setup into a clearly
named utility method makes tests *much* easier to understand.

--Nat

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

    http://xircles.codehaus.org/manage_email


Re: Changing expectations

by Dale King-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

What he probably doesn't realize (and this seems to be a big stumbling block for new users) is that you can break your expectations up into multiple context.checking calls. I know there have been several people come here with the same issue.

The cheat sheet documentation really needs to be updated to make this clear. I submitted a JIRA issue for it.

On Nov 26, 2007 2:59 PM, Nat Pryce <nat.pryce@...> wrote:
On 26/11/2007, Harald Ueland <harald@...> wrote:
> Is there a way to change return values for expectations after they are set?

No.

> I want to do this for some tests where 99 % of the test methods use predefined
> expectations set up from setUp(), but a few needs other return values.
>
> How can this be done without calling a setup method in all the tests?

It cannot.  That's because pulling the common setup into a clearly
named utility method makes tests *much* easier to understand.

--Nat

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

    http://xircles.codehaus.org/manage_email




--
Dale King

Re: Changing expectations

by Wim Deblauwe :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

is there already documentation on this?

regards,

Wim
Dale King-2 wrote:
What he probably doesn't realize (and this seems to be a big stumbling block
for new users) is that you can break your expectations up into multiple
context.checking calls. I know there have been several people come here with
the same issue.

The cheat sheet documentation really needs to be updated to make this clear.
I submitted a JIRA issue for it.

On Nov 26, 2007 2:59 PM, Nat Pryce <nat.pryce@gmail.com> wrote:

> On 26/11/2007, Harald Ueland <harald@hueland.net> wrote:
> > Is there a way to change return values for expectations after they are
> set?
>
> No.
>
> > I want to do this for some tests where 99 % of the test methods use
> predefined
> > expectations set up from setUp(), but a few needs other return values.
> >
> > How can this be done without calling a setup method in all the tests?
>
> It cannot.  That's because pulling the common setup into a clearly
> named utility method makes tests *much* easier to understand.
>
> --Nat
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


--
Dale King

Re: Changing expectations

by Nat Pryce :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It's been in the cheat sheet and cookbook for a while.  It's also now
in the Javadoc of the Mockery.checking method.

--Nat

2009/5/11 Wim Deblauwe <wim.deblauwe@...>:

>
> Hi,
>
> is there already documentation on this?
>
> regards,
>
> Wim
>
> Dale King-2 wrote:
>>
>> What he probably doesn't realize (and this seems to be a big stumbling
>> block
>> for new users) is that you can break your expectations up into multiple
>> context.checking calls. I know there have been several people come here
>> with
>> the same issue.
>>
>> The cheat sheet documentation really needs to be updated to make this
>> clear.
>> I submitted a JIRA issue for it.
>>
>> On Nov 26, 2007 2:59 PM, Nat Pryce <nat.pryce@...> wrote:
>>
>>> On 26/11/2007, Harald Ueland <harald@...> wrote:
>>> > Is there a way to change return values for expectations after they are
>>> set?
>>>
>>> No.
>>>
>>> > I want to do this for some tests where 99 % of the test methods use
>>> predefined
>>> > expectations set up from setUp(), but a few needs other return values.
>>> >
>>> > How can this be done without calling a setup method in all the tests?
>>>
>>> It cannot.  That's because pulling the common setup into a clearly
>>> named utility method makes tests *much* easier to understand.
>>>
>>> --Nat
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list please visit:
>>>
>>>    http://xircles.codehaus.org/manage_email
>>>
>>>
>>
>>
>> --
>> Dale King
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Changing-expectations-tp13949061p23479296.html
> Sent from the jMock - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>



--
http://www.natpryce.com

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

    http://xircles.codehaus.org/manage_email