缺少方法异常

时间:2012-04-12 15:36:22

标签: 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)

任何人都可以提供帮助

1 个答案:

答案 0 :(得分:0)

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