Feignクライアントを呼び出してユニットテストを行う


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の依存を導入する必要があることを覚えています.