user534009
user534009

Reputation: 1479

Java JUnit test case

For example, in a method

public void divide(Integer a){
 //.....
}

In a Java test, we need to test a parameter as String, null, 0, Long .... , do we have a tool which will automatically test these all cases ?

Thanks

Upvotes: 1

Views: 421

Answers (3)

Neel
Neel

Reputation: 2100

Why not use JUnit 4 with a Parameterized test case? JUnit 3 did not support parameterized test cases OOTB, but JUnit 4 has specific API to accept arguments and invoke your test case using those parameters as input. Should that be feasible in your case?

Upvotes: 0

Itay Maman
Itay Maman

Reputation: 30733

First, the compiler will not let you pass String nor Long so there's no point in unit-testing these.

Second, while there are some tools like the one you're describing, I wouldn't recommend them. Effective unit testing is not about trying to cover as much of the state space as possible (because the state space is infinitely large). It is about the wise choice of the "significant" cases. The one who decides what is considered to be significant is you, the programmer.

Upvotes: 5

planetjones
planetjones

Reputation: 12633

Well you can write this yourself using a JUnit TestCase. I don't know of any free tools which will automatically bombard it with all possible inputs to see how it will react, but I do know of the AgitarOne software product (commercial) which does this kind of testing. It's called agitation and lets you explore how your code behaves with nulls, max values, min values, etc.

Upvotes: 1

Related Questions