Help coderanch get a
new server
by contributing to the fundraiser
  • 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Some Basic jUnit questions!

Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am familiar with the basic usage of jUnit and have integrated it with Eclipse to gain a working knowledge. But, I would appreciate if someone can answer the following doubts that I came across during my jUnit testing.

I was testing a String multiplier class with a multiply() method that takes 2 numbers as inputs (as String) and returns the result number (as String)

I have done the implementation and created a test class with the following test cases involving the input String parameter as
1) valid numbers
2) characters
3) special symbol
4) empty string
5) Null value
6) 0
7) Negative number
8) float
9) Boundary values
10) Numbers that are valid but their product is out of range
11) numbers will + sign (+23)

1) I'd like to know if "each and every" assertEquals() should be in it's own test method? Or, can I group similar test cases like testSpecialCharactersArguments() to contains all asserts involving special characters?

2) If testing an input value like character ("a"), do I need to include test cases for ALL scenarios?
"a" as the first argument
"a" as the second argument
"a" and "b" as the 2 arguments

3) As per my understanding, the benefit of these unit tests is to find out the cases where the input from a user might fail and result in an exception. And, then we can give the user with a meaningful message (asking them to provide valid input) instead of an exception. Is that the correct? And, is it the only benefit?

4) Are the 11 test cases mentioned above sufficient? Did I miss something? Did I overdo? When is enough?

5) Following from the above point, have I successfully tested the multiply() method?

Thanks for your input.
This will take every ounce of my mental strength! All for a tiny ad:
We need your help - Coderanch server fundraiser
    Bookmark Topic Watch Topic
  • New Topic