今日份鸡汤:最好的日子或许就是:每天能把计划里的事情,一一打勾✔做完。哪怕目标小小的,心里却满满的~
前提:
单元测试代码写在src/test/java目录下
单元测试类命名为*Test,前缀为要测试的类名
示例:
启动项目,可以测试本jar提供的服务,不启动服务,改为远程服务地址,可以测试远程jar提供的服务。
其中
@EnableFeignClients(clients = UserControllerTest.UserServiceFeignClient.class)
类似我们实际应用调用相关服务一样。
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = UserControllerTest.class)
@Import({ FeignAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class })
@EnableFeignClients(clients = UserControllerTest.UserServiceFeignClient.class) public class UserControllerTest {
@FeignClient(value = "loan-server", url = "http://localhost:9070/")
public interface UserServiceFeignClient extends UserServiceClient {
}
@Autowired
private UserServiceFeignClient userServiceFeignClient;
@Test
public void getUser() {
User user = userServiceFeignClient.getSDKUserById(1);
System.out.println(user);
}
}
网友评论