加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

groovy – Spock测试:在“where:”块完成后清理

发布时间:2020-12-14 16:32:38 所属栏目:大数据 来源:网络整理
导读:我有2种测试方法. 它们都执行where块的每一行,我需要清理add和amp;放松方法. 我已经尝试过cleanup block,void cleanup(),def cleanupSpec(),非套装. 如何在具有“where:”块的特定方法之后显式运行清理? def "Add"() { setup : expect : where: }def "Rela
我有2种测试方法.

它们都执行where块的每一行,我需要清理add和amp;放松方法.

我已经尝试过cleanup block,void cleanup(),def cleanupSpec(),非套装.

如何在具有“where:”块的特定方法之后显式运行清理?

def "Add"() {
   setup :
   expect : 
   where:
    }

def "Relax"() {
   setup :
   expect : 
   where:     
    }

解决方法

您可以在方法中使用清理块,如下所示:

@Unroll
def "a method that tests stuff"(){
  given: 
    def foo = fooDAO.save(new Foo(name: name))
  when: 
    def returned = fooDAO.get(foo.id)
  then:
    returned.properties == foo.properties
  cleanup:
    fooDAO.delete(foo.id)
  where:
    name << ['one','two']
}

每次测试迭代时,“清理”块将运行一次.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读