Employee Service 테스트를위한 테스트 클래스를 만들고, 모든 것이 잘 작동합니다. 다른 함수에서 Field를 사용할 때를 제외하고는 null을 얻습니다.Groovy 클래스의 필드 선언 Spock 프레임 워크 유닛 테스트 케이스
// field
Employee employee;
// this will be assigned to return of below
employee= employeeService.create(emp);
// this(employee) gets null
지금 무엇을 원하는되어
아래는 내 코드, 삭제 테스트 기능에 대한 employeeService.remove(employee.getId);
을 사용하는 것입니다. 친절하게 제안하기
나는 groovy를 처음 사용합니다.
package services.employee
import spock.lang.Specification
@ContextConfiguration(loader = SpringApplicationContextLoader.class,classes = Application.class)
class EmployeeSpec extends Specification{
@Autowired
EmployeeService employeeService;
Employee response = null;
def "Check if Employee exists"(){
setup:
long empid = 43;
when:
empid > 0
then:
employeeService.getEmployee(empid);
}
def "Find all Employee"(){
setup:
when:
def res = employeeService.getAllEmployees();
then:
res.size()>0;
}
def "Insert a New Employee"(){
setup:
Employee employee = new Employee();
employee.setName("Ajit Singh");
employee.setCity("Delhi");
employee.setAge(34);
when:
response = employeeService.createEmployee(employee);
then:
response.getName().equals("Ajit Singh");
}
def "Updating an Employee"(){
}
def "delete an Employee"(){
setup:
if (response.equals(null))
println("Object is null");
when:
employeeService.removeEmployee(response.empID)
then:
def res = employeeService.find(response.empID);
res == null;
}
}
글쎄, 당신의 대답은 매우 매력적입니다 –