views:

28

answers:

2

My team has a set of POJO's that we build up to pass into our code and test various functions. For example we have an Address class which contains address information.

It doesn't make sense to constantly rebuild this class every time we have to whack an address onto an object to test something. I am thinking that something like Rails' fixtures would be good, but simply having some sane package and class in the test tree to store all these would be nice.

Any ideas? Does JUnit have any built in tools to help with this?

+1  A: 

JUnit's parameterised tests may be what you want. You can set up a collection of data (in your case, your POJOs) and run your tests using these as parameters. So you don't need to rewrite tests when you add new example data.

Brian Agnew
A: 

I found the xUnit Patterns book very helpful for this kind of stuff. You might find the Creation Method pattern useful.

Set up the test fixture by calling methods that hide the mechanics of building ready-to-use objects behind Intent Revealing Names.

Follow the link for lots of detail about implementation and design choices. If that doesn't specifically help, check out some of the other fixture setup patterns.

Don Kirkby