junit4 - Paramterized Testing with Junit -


how can test following method parameterized testing in junit

public class math {     public static int add(int a, int b) {           return + b;     } } 

i wish know how parameterized testing junit implemented test method, when want test 10 different args.

the test class must have annotation @runwith(parameterized.class) , function returning collection<object[]> should marked @parameters , constructor accepting inputs , expected output(s)

api: http://junit.sourceforge.net/javadoc/org/junit/runners/parameterized.html

 @runwith(parameterized.class)  public class addtest {         @parameters         public static collection<object[]> data() {                 return arrays.aslist(new object[][] {                                 { { 0, 0, 0 }, { 1, 1 ,2},                                    { 2, 1, 3 }, { 3, 2, 5 },                                    { 4, 3, 7 }, { 5, 5, 10 },                                   { 6, 8, 14 } } });         }          private int input1;         private int input2;          private int sum;          public addtest(int input1, int input2, int sum) {                 this.input1= input1;                 this.input2= input2;                 this.sum = sum;         }          @test         public void test() {                  assertequals(sum, math.add(input1,input2));         }  } 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -