【发布时间】:2016-12-13 12:35:16
【问题描述】:
测试
@RunWith(SpringRunner.class)
@SpringBootTest(classes = MockabstractionApplication.class)
public class SimpleTest {
@SpyBean
private SimpleService spySimpleService;
@Before
public void setup() {
initMocks(this);
}
@Test //fails
public void test() throws Exception {
when(spySimpleService.test(1, Mockito.<String>anyVararg())).thenReturn("Mocked!");
}
}
服务
@Service
public class SimpleService {
public String test(int i, String... args) {
return "test";
}
}
测试失败并显示下一条消息:
org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 参数匹配器的使用无效!预计 2 个匹配器,1 个记录:
我必须使用 int 作为第一个参数和任意数量的可变参数。
【问题讨论】: