【发布时间】:2020-11-25 14:29:27
【问题描述】:
我有一个正在尝试测试的方法
@Retryable(value = {SocketTimeoutException.class},
backoff = @Backoff(delay = 10000),
maxAttempts = 4)
public String getNewString(String oldString) throws IOException{
...
}
我已经像这样创建了它的测试用例:
@SpringBootTest
@RunWith(SpringRunner.class)
public class TestStrings {
@Test(expected = SocketTimeoutException.class)
public void testGetNewString() throws IOException {
...
}
一切正常,测试用例运行 4 次,延迟 10 秒。但我想更改@Retryable 的属性,即maxAttempts 从4 到2 和延迟从10 秒到0.5 秒这个特定的测试用例。 我想这样做,以便在运行测试用例时它不应该等待很长时间,并且测试用例应该快速结束,同时还要测试重试功能。
【问题讨论】:
-
你不能,除非你使它们可配置并使用特定的测试配置运行。
-
使用带有属性占位符的
...expression变体。
标签: java spring spring-boot mockito spring-retry