java - What is the proper implementation for test cases which accept similar type of input parameter,same implementation code but different output -


which 1 advisable use out of 2 ?

when there "same implementation" testcode "different output" because "slight difference in input" i.e input1 , input2 has minor difference. "suppose input1 empty list , input2 parameterized list"

let have dummy code 2 possibilities of test classes :

both behaviour achieved same test method i.e :

public class dataprovider{    private static setup(){   }    public static object[][] data_all_behaviour(){    setup();    return new object[][]{                          {"dataforbehavior1",input1,output1},                          {"dataforbehavior2",input2,output2}};                         }   } }   @runwith(junitparamsrunner.class) public class testclass{   @parameters(class=dataprovider.class)   public void test_all_behaviour(string message,input inp, output out){      //execute input , verify output , display message   } } 

here each behaviour ,there separate test method.

@runwith(junitparamsrunner.class)      public class testclass{        public object[][] data_for_behaviour1(){        setup();        return new object[][]{                              {"dataforbehavior1",input1,output1}                             }       }         public void test_behaviour1(string message,input inp, output out){          //execute input , verify output , display message       }     }         public object[][] data_for_behaviour2(){        setup();        return new object[][]{                              {"dataforbehavior2",input2,output2}                             }       }         public void test_behaviour2(string message,input inp, output out){          //execute input , verify output , display message       }     } } 

also provide other possible ways achieve same ?

either acceptable, long using common test helper method instead of copy/paste second option 2 tests. use whichever understandable , team.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -