list of dots

User Manual    [Previous]   

Generic Testing

Generic testcase is an Umple testcase that is defined as generic. This allows you write a test template that has access to the metamodel in order to propagate the template against a number of elements those match a certain pattern. For instance, you can write a generic test that can be generated for each attribute that is string and has a certain prefix 'studentXXX' or a suffix such as 'XXXId'. You can also use regular expression to match attribute name. We can this a fix in the template. Currently, generic tests can be generated for: attributes, methods and associations. Attibutes can be matched using name and type, methods can be matched using name and exact order of parameters and association are matched based on the type of associations and given specfic fixes to handle association variable propagation.

Example


class Student {  
    
    String studentId;
    nameMemebershipId;
    address;
    studentAge;    
    
    
  generic test checkifLogged(String attribute.regex(\w*Age)){
        Student st1 ( "S1425", "John", "Ottawa",20) ;        
        String valueToCheck = st1.get<<attribute>>();  
        
        assertTrue(valueToCheck > 18);
        
        
        }        
        
}  
 
  
      

Load the above code into UmpleOnline

 

Another Example


class Calculator{  
    
       
        1--* Number; 
        
        0..1->* Controller;
    
    
  generic test checkifLogged(0..1->* association){
        Calculator c1 () ;
        Number n1(c1);
        Number n2(c1);                                
        Controller cn1();
        Controller cn2();
        
        c1.addNumber(n1);
        c1.addNumber(n2);

        c1.addController(cn1);
        c1.addController(cn2);

        String numberInList = c1.numberOf<<association.toSingular()>>s();
        
        if(c1.numberOfNumbers() > 2)
        {
        	assertTrue (numberInList > 2);
        }

        else {
        	assertTrue (numberInList < 2)
        }
                                          
        }        
                     
}  
 
 
 
class Number {


} 


class Controller {


}


  
      

Load the above code into UmpleOnline

 

Another Example


class Calculator{  
    
    Integer x;
    Integer y;
    String someString;
        
  Integer  returnInteger (Integer x) { return x+y;}
  
  String  returnStirng (Integer x) { return someString;}
    
    
  generic test checkifLogged(Integer method Integer){
        Calculator c1 ( 4, 5) ;                
        String valueToCheck = p1.get<<method>>();  
        ps1.getValue(<<method>>);    
        boolean isLogged =  p1.checkIsLogged(valueToCheck);        
        assertTrue(logged == "true");                      
        }        
   generic test checkifLogged(String method Integer){
        // code omitted                       
     }                      
}  
 
  
      

Load the above code into UmpleOnline