This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Testing and the fly likes How to structure test cases Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "How to structure test cases" Watch "How to structure test cases" New topic

How to structure test cases

Timmy Ryan
Ranch Hand

Joined: Dec 09, 2007
Posts: 63

I am totally new to unit testing so need some advice on how to structure them.

I have a method in a checkers game that returns an ArrayList of the pieces a player has on a board. Its parameters are the board and whose go it is.
So need less to say there are quite a lot of valid combinations of arguments that can be passed to the method.

Should I have a separate TC for each set of arguments or pass the arguments in as some sort of arguments array?

If more than one test is required for a method is there a naming convention in Junit?
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33132

If you have multiple test methods, the convention is to name them according to what they are testing. For example:
@Test public void invalidMove()

If you have the same exact tests with different parameters/results, you could use the parameterized test case pattern. The implementation is different between JUnit 3.8 and 4.0, but you'll find it searching for "parameterized test case" and your version of JUnit.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Raja Pal
Ranch Hand

Joined: Jul 12, 2004
Posts: 92
Dear Timmy,

You could also try looking at the board positions that are being passed as arguments. If each combinations of positions can be broadly clssified into sets, then you can name the parameterized sets according to the board positions they categorize. However if board and player to go combinations are all unique an array(multi-dimensional) with a data() method to define all positions and a paramterized suite(s) will help you.

Java Pal - Your friend in technology and innovation...India.
I agree. Here's the link:
subject: How to structure test cases
It's not a secret anymore!