grails - 缺少方法异常

标签 grails groovy integration-testing

我当时正在进行集成测试,每次都会丢失方法异常,
这是集成测试的代码

package supasonic

import grails.plugin.spock.IntegrationSpec

class DownloadRequestServiceSpec extends IntegrationSpec {
    def downloadRequestService    

    def 'downloadrequest can be added to the database'(){
        when:'the createDownloadRequest method is called'
            downloadRequestService.createDownloadRequest(123,23,'127.0.0.0')

        then:'download request is added to the database'
            DownloadRequest request = DownloadRequest.read(1)
        and:'contain the correct userId and trackId'
            request.userId == userId
            request.trackId == trackId

        and:'uniqueIdentifer is not blank'
            request.uniqueIdentifier != ''
        and:'ip address is present'
            request.ipAddress == ipAddress
    }
}

其相关服务如下
package supasonic
import com.supajam.net.NetworkUtils
import org.apache.commons.lang.RandomStringUtils

class DownloadRequestService {

    static transactional = true

    def createDownloadRequest(Long trackId,Long userId,String ipAddress) {
        String uniqueCode = RandomStringUtils.random(20, true, true)
        DownloadRequest request = new DownloadRequest(trackId: trackId, userId: userId, ipAddress: ipAddress, uniqueIdentifier: uniqueCode)
        if(request.save(failOnError: true)) {
            return request
        }
        return null
    }
}

我收到此错误:
groovy.lang.MissingMethodException: No signature of method: supasonic.DownloadRequest.save() is applicable for argument types: () values: []
Possible solutions: save(), save(boolean), save(java.util.Map), wait(), any(), wait(long)
    at supasonic.DownloadRequestService.createDownloadRequest(DownloadRequestService.groovy:12)
    at supasonic.DownloadRequestServiceSpec.downloadrequest can be added to the database(DownloadRequestServiceSpec.groovy:12)

任何人都可以帮忙吗

最佳答案

尝试将@Mock(DownloadRequest)添加到测试类中,如http://blog.springsource.org/2011/06/07/countdown-to-grails-1-4-unit-testing/中的示例所示。

关于grails - 缺少方法异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10126938/

相关文章:

json - 如何实现推送通知?

grails - 如何从groovy中的数组中获取常见对象

qt - Selenium Webdriver 支持 Javafx 2.0 Webkit 或 QT5 Webkit(目标 : headless webkit)

java - 使用 Maven 构建单独的 JAR 文件以对自定义类加载器进行单元测试

java - 使用google api java客户端时,是否需要包含google http客户端和google oauth客户端?如何使用 gradle 做到这一点?

grails - grails在createcriteria上的使用顺序

grails - Grails插件依赖性问题,WAR文件缺少插件工件

groovy - 从 Spring Boot 渲染 GORM 类

bash - 使用 bash 与 CMake 和 CTest 进行简单的集成测试?

testing - 使用 Grails 构建测试数据插件创建对象而不保存它