java - 如何在每次测试之前或之后让 Spring Cloud Contract 重置 WireMock
问题描述
我们正在编写一个 Spring Boot 应用程序并使用 Cloud Contract WireMock 支持来存根支持服务。我们的测试类是这样注释的:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@AutoConfigureWireMock(port = 0)
public class Tests...
这工作得很好,除了一件事:我们发现 Spring Cloud 似乎没有在测试之间重置 WireMock,特别是删除存根,因此测试没有被正确隔离。当然,您可以使用@Before
包含 a 的方法自己完成此操作reset()
,但我们想知道这是否是故意的。是否有我们忽略的选项或必须使用的附加注释?
毕竟,@BeforeClass
如果总是执行重置,就不可能在一个方法中定义存根,所以我们想知道开箱即用的反对是什么?
解决方案
The WireMock server can be reset at any time, removing all stub mappings and deleting the request log. If you’re using either of the JUnit rules this will happen automatically at the start of every test case. However you can do it yourself via a call to WireMock.reset()
in Java or sending a POST request with an empty body to http://<host>:<port>/__admin/reset.
To reset just the stub mappings leaving the request log intact send a DELETE to http://<host>:<port>/__admin/mappings.
Hope this is useful.
推荐阅读
- azure - Azure:撤销用户的访问令牌,使他们无法从 Azure 中的移动后端请求数据
- javascript - 为什么我无法捕捉到返回的响应错误?
- c++ - 错误:无法转换 'std::__cxx11::basic_string
::迭代器' - c++ - 如何建立运算符优先级?
- sql - 在 MS Access 中填充字母数字值的条件更新查询
- javascript - 如何使用 Javascript 获取结果
- python - 在python中使用列表对嵌套字典进行排序
- c++ - 以不同的方式平移同一 3D 空间中的两个对象?
- ios - Mac 和 iOS 的核心蓝牙不一致
- c++ - 会员价值在 Tick 上失去价值(c++)