我想寫斯波克框架,而不是JUnit中,嘲諷沒有出現在斯波克工作框架
測試類:
class StudentServiceSpec extends Specification{
@Shared def studentDao
@Shared def studentService
def setupSpec(){
studentDao = Mock(StudentDao)
studentService = new StudentService(studentDao)
}
def "Get Student Details Based on StudentId"(){
setup:
1*studentDao.getStudent(67) >> new Student()
when:
Response response = studentService.getStudent("67")
println "** Response "+response
println "** Response "+response.getEntity()
then:
response != null
}
}
當我使用maven乾淨的安裝命令運行上面的代碼,我得到以下錯誤。
錯誤:
1*studentDao.getStudent(67) >>> new Student() (0 invocations)
如果我使用0*studentDao.getStudent(67) >>> new Student()
我得到response.getEntity()
是null
你可以接受你的自己的回答 – kazanaki
哇,你救了我的夜晚:) thx – radio