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?
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.
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.