Basic jUnit Questions

Posted by Epitaph on Stack Overflow See other posts from Stack Overflow or by Epitaph
Published on 2010-04-26T00:35:11Z Indexed on 2010/04/26 0:43 UTC
Read the original article Hit count: 420

Filed under:
|
|
|

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)

`public String multiply(String num1, String num2);      

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 testInvalidArguments() to contains all asserts involving invalid characters since ALL of them throw the same NumberFormatException ?

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?

© Stack Overflow or respective owner

Related posts about junit

Related posts about testcase