Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JUnit - How to test a method with different values?

I have a method and wish to test it with different values. My question is: how can I write a JUnit test that would test the same method with different values?

like image 621
user722781 Avatar asked Apr 26 '11 17:04

user722781


2 Answers

You can take a look at parametrized tests like in example.

You can also use theories which is more convenient in a lot of cases.

like image 85
Constantiner Avatar answered Nov 20 '22 22:11

Constantiner


JUnit4 supports parameterized tests for just this purpose.

See this tutorial.

like image 5
skaffman Avatar answered Nov 20 '22 22:11

skaffman