You can't possibly write a test to ensure that every single line of
every single method gets called without writing log statements and
parsing the log.

Test your page, test your service.  You can return some flag from the
service method (perhaps a boolean) to indicate whether or not the
service was successful.  You can then output that to the rendered HTML
either in a statement that is for the user OR as a simple hidden span
that can be checked in htmlunit.

If you spend your time trying to ensure that line N+1 *gets called*
when you know that line N does (and line N isn't a branch) I seriously
think you are wasting your time.  Of course line N+1 gets called.  It
has to.

Are you certain that line N gets called?  Can you prove it?  If you
can, then you have proved that line N+1 gets called (unless you get an
exception -- but that depends on how you prove that line N gets
called).

-Mike

On 4/10/06, Dan Adams <[EMAIL PROTECTED]> wrote:
> I would love to use a mock object for this, but I'm not sure of a way to
> instantiate a page class in order to test it. We use mock objects
> extensively elsewhere but I don't know how to set up a tapestry page to
> test it.
>
> On Mon, 2006-04-10 at 11:19 -0400, James Carman wrote:
> > I would use MockObjects for this and the second line would be something
> > like:
> >
> > emailService.sendEmail( params );
> >
> > Then, you give it a mock emailService and make sure it calls it.
> >
> > -----Original Message-----
> > From: Dan Adams [mailto:[EMAIL PROTECTED]
> > Sent: Monday, April 10, 2006 11:16 AM
> > To: Tapestry users
> > Subject: RE: [OT] test case for pages that email
> >
> > No no. Okay lets say I have some code in the page that does this:
> >
> > displayMessage();
> > sendEmail();
> >
> > How do you write a unit test that makes sure that the page actually
> > calls the second line? You could take it out and still have the tests
> > pass.
> >
> > I found a lightweight email server at
> > http://www.ericdaugherty.com/java/mailserver that looks like it could
> > use that.
> >
> > On Mon, 2006-04-10 at 10:52 -0400, James Carman wrote:
> > > You don't typically unit test a mail server.  That's a
> > > deployment/configuration issue.  If you're using JavaMail or Jakarta
> > Commons
> > > Email to send your emails, you can be pretty sure that the emails will go
> > > out if your mail server is available and configured properly.
> > >
> > > -----Original Message-----
> > > From: Dan Adams [mailto:[EMAIL PROTECTED]
> > > Sent: Monday, April 10, 2006 10:50 AM
> > > To: Tapestry users
> > > Subject: Re: [OT] test case for pages that email
> > >
> > > Well, my page is going to display a message to the user letting them
> > > know but that doesn't ACTUALLY mean that the email was sent or the
> > > service was called. The way I have to do it right now is by having the
> > > email sent to me and checking my email manually. I would love to have it
> > > all automated though.
> > >
> > > On Mon, 2006-04-10 at 10:45 -0400, Mike Snare wrote:
> > > > Well, wouldn't you want to indicate to the user that the send was
> > > > successful or not?  If so, you could just look for that.  I know you
> > > > said that the submission doesn't affect the page but don't you want to
> > > > let the user know it worked?
> > > >
> > > > -Mike
> > > >
> > > > On 4/10/06, Dan Adams <[EMAIL PROTECTED]> wrote:
> > > > > Okay, I have a page that, when submitted, sends an email. Now the page
> > > > > uses a service via interface that actually does the emailing and that
> > > > > service is tested separately. But how can I write a test that makes
> > sure
> > > > > that my page actually calls that service and that the email gets sent
> > > > > since that doesn't effect the page in any way that i can test for
> > using
> > > > > htmlunit? Does anyone know of a lightweight mail server analogous to
> > > > > jetty/hsqldb that i could use for testing?
> > > > >
> > > > > --
> > > > > Dan Adams
> > > > > Software Engineer
> > > > > Interactive Factory
> > > > >
> > > > >
> > > > > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > > >
> > > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > >
> --
> Dan Adams
> Software Engineer
> Interactive Factory
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to