【发布时间】:2019-05-10 11:38:19
【问题描述】:
我一直在尝试在 Spring Boot 实现中模拟来自服务的 feign 客户端调用,以编写 Junit 测试用例。
//Service code
@Autowired
private PersonClient personClient;
//Using the personClient
public Person someMethod(){
//Interface defined with URL and all defination
Person person = personClient.getPerson();
}
//Service testing bean
@RunWith(MockitoJUnitRunner.class)
public Class ServiceTest{
@Mock
public PersonClient mockPersonClient;
@Test
public someTestClient(){
when(mockPersonClient.getPerson()).return(new Person("name",12));
Person person = mockPersionClient.getPerson();
assertEquals(new Person("name",12), person);
}
}
上述方法不起作用,我是 feign 客户端的新手,因此不知道如何模拟 feign 客户端界面。
有没有其他方法可以实现上述相同的事情。
【问题讨论】:
标签: spring-boot junit mockito spring-cloud-feign feign