簡體   English   中英

在 grails 2.2.3 單元測試中使用多個 mockFor()

[英]Using multiple mockFor() in grails 2.2.3 unit test

我想為我的 controller 編寫一個單元測試,它在其中使用多個服務。 如何將多個 mockFor() 用於服務? 腫瘤壞死因子。

例如使用 spock 進行測試:

class ExampleControllerUnitSpec extends Specification {
    def anyService
    def anotherService


    def setup() {
        anyService = Mock(AnyService)
        controller.anyService = anyService

        anotherService = Mock(AnotherService)
        controller.anotherService = anotherService
    }

    def "test"(){
        when:
            controller.action()
        then:
            1 * anyService.doSomething() >> "result"
            3 * anotherService.doSomethingElse() >> "result2"
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM