如何解决测试 Feign 客户端
我编写了一个假客户端,我想使用单元测试来测试它是否有效。
就我而言,集成测试不是当前开发阶段的正确方法。
伪装客户端是 null
,我在运行测试时收到 NullPointerException
。
如何自动装配?
伪装客户端
package com.myapp.clients;
import com.myapp.model.StatusResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@FeignClient(name="myClient",url="${feign.clients.my.url}")
public interface myClient {
@RequestMapping(method= RequestMethod.GET,value="/v1/users/{userId}")
StatusResponse getStatus(
@RequestHeader(value = "Auth",required = true) String authorizationHeader,@RequestHeader(value = "my_tid",required = true) String tid,@PathVariable("userId") String userId);
}
测试:
package com.myapp.clients;
import com.intuit.secfraudshared.step.broker.model.StatusResponse;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
public class MyClientTest {
@Autowired
MyClient myClient;
@Test
public void testmyClient_status200() {
StatusResponse myResponse = myClient.getStatus("","tidTestSample","4626745161770145");
Assert.assertNotNull(iusResponse);
}
}
如何自动装配 MyClient?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。