银杏清除失败

时间:2019-07-10 23:31:43

标签: go ginkgo gomega

我正在用银杏编写测试规范。

我的测试具有以下结构:

It("Setup X, Y, Z resources and check conditions" func() {
    // setup resources. 
    // assert certain conditions using
    //cleanup resources
}) 

我的问题是,断言失败时如何执行清理。如果我为此目的使用afterEach块,那么它将在所有测试规范上执行相同的清理,这表明清理消息失败。

使用银杏叶清除失败的推荐方法是什么?

1 个答案:

答案 0 :(得分:0)

您可以将此测试保留在单独的上下文中。然后 afterEach (仅此一次)将仅适用于该情况下的所有 It

Context("Setup X, Y, Z resources and check conditions", func() {
    BeforeEach(func() {
        // do ...
    })

    AfterEach(func() {
        // do clean up
    })

    It("should pass the condition", func() {
        // do ...
    })
})
相关问题