aspose file tools*
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
JavaRanch » Java Forums » Engineering » Testing
Bookmark "How to structure test cases" Watch "How to structure test cases" New topic
Author

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30293
    
150

Timmy,
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.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, 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: http://aspose.com/file-tools
 
subject: How to structure test cases