【问题标题】:ginkgo cleanup on failure银杏清理失败
【发布时间】:2019-07-11 11:56:07
【问题描述】:

我正在用 Ginkgo 编写测试规范。

我的测试具有以下结构:

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

我的问题是,断言失败时如何执行清理。如果我为此目的使用 afterEach 块,那么它会对所有测试规范执行相同的清理,这会显示一堆清理消息失败。

推荐使用银杏清除故障的方法是什么。

【问题讨论】:

    标签: go ginkgo gomega


    【解决方案1】:

    您可以将此测试单独保存在上下文中。那么 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 ...
        })
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-29
      相关资源
      最近更新 更多