[ajug-members] JUnit testing

Dan Glauser dan at roundboxmedia.com
Thu Sep 30 19:09:25 EDT 2004


Level of testing is an interesting question.  There's really not too
many good ways to qualify this.  I usually focus on a three different
levels:

Basic Functionality Tests
Q: Does the feature work in a general case?
I will write a couple of tests to make sure the feature works in a basic
sense.

Boundary Condition Tests/Negative Test
Q: What are the limits of the feature?
Q: What type of input should not work with this feature?
Q: How is the feature supposed to handle error conditions?
Some of these can be hard to test automatically (like dropping the
database).
This level results in quite a few tests.

Integration Tests
Q: Does this feature work with other features?
Q: How can this feature be combined with other features?
These can grow in complexity very quickly, think about all possible
combinations of just twenty features and you'll get the idea.  I usually
focus on testing combinations that are common and combinations that I
feel may present a problem.

Now, how much of this do I usually do?  I ALWAYS shoot for Basic
Functionality tests, I try and do Boundary Condition tests where I think
there may be an issue and I often don't do Integration Tests due to the
difficulty in setting them up and automating them.  I'll often do these
by hand. 

When I do find a bug the first thing I do is to write a test for it. 
That makes it easier to recreate, plus it gives me a regression test so
I can help to ensure that a problem area doesn't reoccur.

I will sometimes use mock objects but I prefer to create a database load
specifically for testing.  Using your best judgment here is my advice. 
I find mock objects a bit of a pain because you have to recompile to use
the "real" thing.  I'd rather swap out database loads at runtime.  If
your database is far away or you have to talk to five dba's just to get
things going then mock objects might be your best option.

In webapps I always write JUnit tests for my model layer.  Besides being
essential to the application I find it to be really easy, help with
development and generally speed things up.  Although our last AJUG
speaker Justin Gehtland is unaware, it is possible to unit test EJBs
with JUnit.  In fact, we have two J2EE webapps here with EJBs that are
both unit tested.  Every EJB.  Check out:

http://www.junitee.org/

In conclusion, I never feel that I do enough unit testing.  The more I
do the better my code turns out.  In reality I use a "best try" approach
and do what I can.  Some testing is much better than none.  But no
amount of testing guarantees that something will work.  It just
increases your changes of getting it write.

My 2c's.

Regards,

-- 
Dan Glauser
Director of Serverside Development
Roundbox Media
dan at roundboxmedia.com
W: 404.877.0107


On Thu, 2004-09-30 at 18:05, Barnes, Michael wrote:
> I have a question about junit and unit testing in general.
> 
> First, what is considered the right level of testing. Second, how do people
> test a database application. Do you use mock objects or do you set up a
> database that will support you unit tests.
> 
> Thanks
> Mike Barnes
> 
> 
> **************************************************************
> This message, including any attachments, contains confidential information intended for a specific individual and purpose, and is protected by law.  If you are not the intended recipient, please contact sender immediately by reply e-mail and destroy all copies.  You are hereby notified that any disclosure, copying, or distribution of this message, or the taking of any action based on it, is strictly prohibited.
> TIAA-CREF
> **************************************************************
> 
> _______________________________________________
> ajug-members mailing list
> ajug-members at ajug.org
> http://www.ajug.org/mailman/listinfo/ajug-members





More information about the ajug-members mailing list