First it looks like you're using an ancient version of EasyMock... Is that intentional?

Seems like you're trying to do the wrong things in the setUp method. I'd suggest restructuring it like: (using the a more modern (but still ~2.5 years old EasyMock))

You're only testing are the correct calls proxied through to the DAO (and any other business logic/manipulation you need to do). Since you're mocking the DAO, there's no real need to build up a list of cbts anywhere, I haven't ripped it out yet, but its really not needed... Even for testing exceptions/duplicates, it won't be needed since all you need to do is set the expectation to be expect().andThrow().... to check if you handle those cases correctly.

Jason Ferguson
Ranch Hand

Joined: Sep 16, 2007
Posts: 47

posted Mar 05, 2008 20:37:00

0

Originally posted by Eric Nielsen: First it looks like you're using an ancient version of EasyMock... Is that intentional?

Its an unfortunate necessity. EasyMock 2.X requires Java 5.0. It seems that the only way to get my app server upgraded out of the stone age would involve violence, and I've decided that it's not worth ending up in jail for.

Seems like you're trying to do the wrong things in the setUp method. I'd suggest restructuring it like: (using the a more modern (but still ~2.5 years old EasyMock))

// Snipped out code

You're only testing are the correct calls proxied through to the DAO (and any other business logic/manipulation you need to do). Since you're mocking the DAO, there's no real need to build up a list of cbts anywhere, I haven't ripped it out yet, but its really not needed... Even for testing exceptions/duplicates, it won't be needed since all you need to do is set the expectation to be expect().andThrow().... to check if you handle those cases correctly.

Okay, back to the books then. I'm only a couple of days into doing unit testing, and haven't used expect().andThrow() yet.

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com