go - 银杏清理失败
问题描述
我正在用 Ginkgo 编写测试规范。
我的测试具有以下结构:
It("Setup X, Y, Z resources and check conditions" func() {
// setup resources.
// assert certain conditions using
//cleanup resources
})
我的问题是,断言失败时如何执行清理。如果我为此目的使用 afterEach 块,那么它会对所有测试规范执行相同的清理,这会显示一堆清理消息失败。
用银杏清理失败的推荐方法是什么。
解决方案
您可以将此测试保存在单独的上下文中。然后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 ...
})
})
推荐阅读
- python - scattermapbox plot.ly dash 没有出现
- r - 将 ggplot2 与 Rshiny 一起使用:ggplot y 轴上显示的级别不正确
- c++ - 递归函数的帕斯卡三角形
- android - 双簧管音频流格式:int16_t格式会消失吗?
- laravel - 递归地将模型添加到 Scout Laravel
- node.js - Node.JS 致命错误:堆限制附近的无效标记压缩分配失败?
- sql - 在几天内运行列中唯一字符串值的总数
- javascript - 查找模式,然后通过结束新行拆分
- java - 为什么它在字符串中返回错误的重复次数?
- react-native - 选项卡导航器中的图标图像被切断 - 反应原生