• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to structure test cases

 
Ranch Hand
Posts: 63
IntelliJ IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic