You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Joe Germuska <Jo...@Germuska.com> on 2004/12/01 00:19:18 UTC
Re: Experiences with MockObjects for Servlet testing?
At 5:13 PM +0000 11/23/04, Gareth Webbley wrote:
>I don't know if this is the correct way to do it but if you call
>setupGetAttribute on the MockServletContext with the key that you require and
>a null value, when the code you want to test calls getAttribute it will get a
>null value (which I assume is what you want in the test) and the
>AssertionFailedError will not be seen.
>
>I think the idea is you call setupGetAttribute with each attribute you expect
>the code you are testing to try to get even if you want the code to receive a
>null value. If the code attempts to get an attribute which you haven't told
>the MockServletContext about you get the AssertionFailedError.
Gareth:
This moved me further, but only to another error:
1)
testActionCaching(org.apache.struts.chain.TestCreateAction)junit.framework.AssertionFailedError:
attributes.actions has run out of objects.
The JavaDoc for the Mock servlet objects is hopeless. Can you point
to any other good docs for using the MockObjects for servlet testing?
Joe
--
Joe Germuska
Joe@Germuska.com
http://blog.germuska.com
"Narrow minds are weapons made for mass destruction" -The Ex
Re: Experiences with MockObjects for Servlet testing?
Posted by Gareth Webbley <ga...@webbleysoftware.freeserve.co.uk>.
Hi Joe,
Sorry I don't know of any better documentation.
The way I understand things is that mockobjects allows you to check that the
code you are testing requests attributes the exact number of times you
expect. So for example if you are testing some code which should call
getAttribute on the actions key 3 times then you need to call
setupGetAttribute for the actions key 3 times. This adds 3 separate objects
to the attributes which will be returned for the actions key at each of the 3
getAttribute requests. If your code requests the actions attribute more
times than you've called setupGetAttribute for that key then you get the
exception you have here. Equally if the code you were testing only called
getAttribute twice for the actions key then you would also get an exception
saying that there were attributes left over for that key.
HTH
Gareth
On Tuesday 30 November 2004 23:19, Joe Germuska wrote:
> At 5:13 PM +0000 11/23/04, Gareth Webbley wrote:
> >I don't know if this is the correct way to do it but if you call
> >setupGetAttribute on the MockServletContext with the key that you require
> > and a null value, when the code you want to test calls getAttribute it
> > will get a null value (which I assume is what you want in the test) and
> > the
> >AssertionFailedError will not be seen.
> >
> >I think the idea is you call setupGetAttribute with each attribute you
> > expect the code you are testing to try to get even if you want the code
> > to receive a null value. If the code attempts to get an attribute which
> > you haven't told the MockServletContext about you get the
> > AssertionFailedError.
>
> Gareth:
>
> This moved me further, but only to another error:
> 1)
> testActionCaching(org.apache.struts.chain.TestCreateAction)junit.framework.
>AssertionFailedError: attributes.actions has run out of objects.
>
> The JavaDoc for the Mock servlet objects is hopeless. Can you point
> to any other good docs for using the MockObjects for servlet testing?
>
> Joe
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org