2

私は統合テストに取り組んでいましたが、毎回メソッドの例外がありません。統合テストのコードは次のとおりです。

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)

誰でも助けることができます

4

1 に答える 1

0

http://blog.springsource.org/2011/06/07/countdown-to-grails-1-4-unit-testing/の例のように、テストクラスに @Mock(DownloadRequest) を追加してみてください。

于 2012-06-01T12:30:34.670 に答える