import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.feign.FeignAutoConfiguration;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.List;
import static org.junit.Assert.*;
/**
* @author ryx
* @ProjectName project
* @Description: feign测试
* @date 2018/9/21 002116:47
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = B类.class)
@Import({FeignAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class})
@EnableFeignClients(clients = C类.A类.class)
public class C类{
@FeignClient(value = "feign客户端名称", url = "Host:Port")
public interface A类 extends B类{
}
@Autowired
private A类 a;
/**
* 方法功能描述: feign测试
* @return: void
* @auther: ryx
* @date: 2018/9/21 0021 17:00
*/
@Test
public void queryEmployeeByDeptId() {
Object a =a.getxxx();
Assert.assertEquals(expectedValue, a);
}
}
以上只是我常用的一种方法,记得需要引入spring test的依赖。