Thanks, Jan, for the link. I actually didn't know about theories.

Fabrizio, could you provide an example where it is advantageous to
know that a specific test failed? When the test fails you can look at
the trace and find out the problem. If tests would be separate, I
agree it would be faster/easier to locate the issue, but does it
outweigh the redundancy that you get by having similar test methods?

In my experience I spend more time adjusting test cases due to code
changes as opposed to tracking down failing tests.

Regards,
Emilis

On Nov 25, 4:49 pm, "Fabrizio Giudici" <[email protected]>
wrote:
> On Fri, 25 Nov 2011 15:28:43 +0100, Emilis <[email protected]>
> wrote:
>
> > Hello, Posse people,
> > I would like to get some opinions on how to write the unit tests for
> > the following scenario.
>
> > Let's assume that we are testing some method which should generate to
> > events: eventA and eventB. Unit test could look like this:
>
> > testEventA() {
> >   // 1. mock eventA listener
> >   // 2. setup the test case
> >   // 3. invoke method
> >   // 4. verify that eventA listener was called correctly
> >   // 5. verify that eventA contains correct values
> > }
>
> > testEventB() {
> >   // 1. mock eventB listener
> >   // 2. setup the test case
> >   // 3. invoke method
> >   // 4. verify that eventB listener was called correctly
> >   // 5. verify that eventB contains correct values
> > }
>
> > Assuming that steps 2 and 3 are the same for both tests, do you keep
> > both tests separate (as above) or do you write testEventAandEventB()
> > instead? and why?
> > Bonus question. Let's assume that both tests are testing the same
> > event now and the only difference between them is steps 2 and 3. What
> > would be your approach? again, why?
>
> Separate tests in any case if they can fail independently. This doesn't
> mean that you can't factor out some common preparation / assertion code,
> of course. If for some reason they cannot fail independently, or there's
> no strong advantage in knowing that only one failed, I'd prefer to keep
> the same two separate tests, but with a lesser strength.
>
> --
> Fabrizio Giudici - Java Architect, Project Manager
> Tidalwave s.a.s. - "We make Java work. Everywhere."
> [email protected]http://tidalwave.it-http://fabriziogiudici.it

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" 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/javaposse?hl=en.

Reply via email to