Changes between Version 43 and Version 44 of ProgrammingGuidelines


Ignore:
Timestamp:
07/12/11 16:51:54 (8 years ago)
Author:
welberge
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ProgrammingGuidelines

    v43 v44  
    241241assertThat(someCollection,Matchers.<String>empty()); 
    242242}}} 
     243=== Parameterized testing === 
     244Parameterized test classes allow the reuse of test case logic with different input parameter values. Each test case in a parameterized test is executed multiple times, with a different (pre-specified) set of input parameter values.  
     245The default parameterized test functionality in JUnit does not communicate the values of the parameters when the parameterized test fails. The HmiTestUtils package provides LabelledParameterized, which fixes this by allowing you to add a  
     246label to each parameter instance. 
     247 
     248Example: 
     249{{{ 
     250@RunWith(LabelledParameterized.class) 
     251public class SchedulerParameterizedIntegrationTest 
     252{ 
     253    @Parameters 
     254    public static Collection<Object[]> configs() throws Exception 
     255    { 
     256        Collection<Object[]> objs = new ArrayList<Object[]>(); 
     257         
     258        for(int i=0;i<..;i++) 
     259        {        
     260          Object obj[] = new Object[2]; 
     261          SpeechEngineFactory sp = ... 
     262          obj[0] = "SpeechPlanner = " + sp.getType();//label 
     263          obj[1] = sp;                               //test parameter 1 
     264          objs.add(obj);         
     265        } 
     266        return objs; 
     267    } 
     268    private SpeechEngineFactory speechEngineFactory;  
     269 
     270    public SchedulerParameterizedIntegrationTest(String label, SpeechEngineFactory sv) 
     271    { 
     272       speechEngineFactory = sv; 
     273    } 
     274 
     275    @Test 
     276    public void test() 
     277    { 
     278       assertSomething(speechEngineFactory); 
     279    } 
     280    ... 
     281} 
     282}}} 
    243283 
    244284[[ViewTopic()]]