• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to structure test cases

 
Timmy Ryan
Ranch Hand
Posts: 63
IntelliJ IDE Java Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 34218
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Raja Pal
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic