dimanche 31 juillet 2016

Combining EasyTest/JUnitParameter alike with ObjectMother pattern

I was wondering whether I can use annotations with tools like JUnitParameter with an Object mother pattern. For example.

class EmployeeObjectMother {
    @DataProvider(filepath = "ceoEmployee.csv") 
    public static Employee getCeoEmployee(@Param String name, @Param Double salary) {
        Employee employee = new Employee(name, salary);
        return employee;
    }
}

class EmployeeTest {

   // some annotation magic
   // parameter = EmployeeDataprover.getCeoEmployee 
   void shouldBeAnEmployee(Employee employee) {
       // do some testing
   }

}

In addition if it would be nice to have list of Employees through annotation magic such as:

   // annotation magic
   // annotation parameter parameter: List of employees and run for each of the item from the 
   // list
   void shouldBeAnEmployee(Employee employee) {
   }

I am not sure this is even possible or exists. If not then what is the way we can achieve Object Mother obtain its parameters and avoid coupling it with literal file name in its code. Please enlighten me.

Thanks

Aucun commentaire:

Enregistrer un commentaire