我正在使用Spring-Breaker 项目为我的代码实现一个断路器解决方案,并为此编写测试用例。
考虑以下示例:
@CircuitBreaker
methodA() {
//some code
gatewayServiceCall()
//some code
}
我需要测试 methodA 并使用 CircuitBreaker 超时使其失败,所以我编写了一个模拟这个的测试类。
setup() {
gatewayService = mock(GatewayService.class);
when(gatewayService.methodName().thenReturn(something);
}
@Test
testMethodA() {
methodA();
}
我如何确保我调用了 methodA() 但也模拟了 gatewayServiceCall。
我希望这个问题很清楚。如果不是,请告诉我。我将尝试进一步详细说明。
谢谢。