MakeAWishFoundation / SwiftyMocky

Framework for automatic mock generation. Adds a set of handy methods, simplifying testing. One of the best and most complete solutions, including generics support and much more.
MIT License
1.03k stars 104 forks source link

Verifying async logic #321

Open DesmanLead opened 2 years ago

DesmanLead commented 2 years ago

It's a common use-case to verify that the method will be called at some moment in the future in a given timeout. It's possible to implement this using Perform, but another version of Verify (e.g. Expect?) would be really handy. So the API design might be as follows:

    override func setUp() {
        super.setUp()

        interactor = MyInteractor()
        interactor.service = mockService
    }

    func testThatInteractorHandlesRefresh() async throws {
        // given
        Given(mockService, .obtainData(...))

        // when
        await interactor.refresh() // calls obtainData asynchronously inside

        // then
        await Expect(mockService, .obtainData(...)) // default timeout
        await Expect(mockService, .obtainData(...), timeout: .seconds(1))
    }

What do you think? It doesn't look hard to implement, so you can just point the right spot to add this.