gojuno / minimock

Powerful mock generation tool for Go programming language
MIT License
577 stars 38 forks source link

Proposal: add .Panic() alongside .Return(...) for interrupting a test #51

Closed unkeep closed 6 months ago

unkeep commented 3 years ago

It would be useful for testing expectations which do not return an error or the error does not interrupt a flow.

example code:

func foo(dep Dependency) {
    dep.doSmth1(...)
    dep.doSmth2(...)
}

example test:

It("should doSmth1", func(){
    depMock.Expect(...).Panic()
    Ω(func(){foo(depMock)}).Should(Panic())
})

Of course the same could be done by adding panic() to the end of Inspect func, but the proposed way is more natural and shorter

hexdigest commented 6 months ago

Hey, you can achieve the same using Set:

It("should doSmth1", func(){
    depMock.Set(func(...) {
       panic("is good for you")
    })
    Ω(func(){foo(depMock)}).Should(Panic())
})

I don't think it deserves a special helper.