Verify Spock mock with specified timeout

前端 未结 4 463
灰色年华
灰色年华 2021-01-04 21:20

In Mockito there is option to verify if mock method has been called, and specify timeout for this verification (VerificationWithTimeout), for example:



        
4条回答
  •  感动是毒
    2021-01-04 22:24

    Using PollingConditions and a boolean variable, the following example evaluates a function until it satisfies an interaction.

    def "test the config watcher to reload games if a new customer directory is added"() {
    
    given:
    def conditions = new PollingConditions(initialDelay: 1, timeout: 60, factor: 1.25)
    def mockGameConfigLoader = Mock(GameConfigLoader)
    def gameConfigWatcher= new GameConfigWatcher(mockGameConfigLoader)
    boolean gamesReloaded = false
    
    when:
    conditions.eventually {
        gameConfigWatcher.listenEvents()
        assert gamesReloaded
    }
    
    then:
    1 * mockGameConfigLoader.loadAllGameConfigs() >> {
        gamesReloaded = true
    }
    0 * _
    

    }

提交回复
热议问题