这是删除操作,我想进行单元测试和
def deleteRoutineTable()
{ def deleteRoutineTableId=params.id;
def routineTable=RoutineTable.get(deleteRoutineTableId);
routineTable.delete()
redirect(action: "routineTable")
}
这是测试代码......但这显示错误..as
def newRoutintable=new RoutineTable(id:1,name: "routine",institution:1,endTime: new Date(),startTime: new Date())
newRoutintable.save(flush:true)
newRoutintable.list().size()+1
when:
controller.deleteRoutineTable()
then:newRoutintable.list().size()-1
}
失败:|
testDelete(routine.RoutineTableControllerSpec)
|
java.lang.NullPointerException: Cannot invoke method delete() on null object
at routine.RoutineTableController.deleteRoutineTable(RoutineTableController.groovy:54)
at routine.RoutineTableControllerSpec.testDelete(RoutineTableControllerSpec.groovy:60)