我有困難包含在域這樣的方法進行單元測試:的Grails - 單元測試
這是域類
class UserRole implements Serializable {
User user
Role role
static void removeAll(User user) {
executeUpdate 'DELETE FROM UserRole WHERE user=:user', [user: user]
}
}
然後在服務:
class CorporateUserService {
def delete (def cifUserInstance) {
def userDetail,users,userRole
userDetail=UserDetails.findById(cifUserInstance.userDetails.id)
users=User.findById(userDetail.user.id)
userRole=UserRole.removeAll(users)
}
}
並在單元測試中:
void testDelete(){
def cifUserService = new CorporateUserService()
mockDomain(UserRole,[])
def newuserRole2=UserRole.create(user,role2)
def newuserRole=UserRole.create(user,role)
newuserRole.executeUpdate 'DELETE FROM UserRole WHERE user= :user',[user: user]
try{
cifUserInstance = cifUserService.delete(cifUser)
}
catch(RuntimeException e){
println e
}
}
我有這樣的錯誤:
「groovy.lang.MissingMethodException: com.logika.corp.security.UserRole.executeUpdate() 適用於參數類型: 沒有方法的簽名 ( java.lang.String中, java.util.LinkedHashMap中)的值: [DELETE FROM的UserRole WHERE用戶= :用戶,[用戶:用戶1]]」
任何人都可以知道如何解決此誤差Δθ