假客户端进行API测试

时间:2018-08-14 22:36:37

标签: netflix-feign spring-cloud-feign feign

我正在尝试创建一个伪装客户端,并将其用于在预生产环境中测试我的API。我写了一个客户端,但是在我的测试课程中没有解决。

我还写了一个包装器API,看到该API调用成功。所以我认为假冒客户不成问题。

我是否需要额外的配置才能在测试中使用客户端?

假冒客户-

@FeignClient(name = "country-service-client", url = "http://country.io")
public interface CountryServiceClient {

    @RequestMapping(method = RequestMethod.GET, value = "/names.json", produces = "application/json")
    String getCountries();
}

测试-

public class CountryTest {

    Logger logger = LoggerFactory.getLogger(CountryTest.class);
    private static final JsonParser parser = JsonParserFactory.getJsonParser();

    @Autowired
    private CountryServiceClient countryServiceClient;

    @Test
    public void testServiceExceptionValidationError() {
        String countries = countryServiceClient.getCountries();

        Map<String, Object> countryMap = parser.parseMap(countries);

        String countryArray[] = new String[countryMap.size()];
        logger.info("Size of countries " + countryArray.length);

        Assert.assertNotNull(countryArray);
    }
}

0 个答案:

没有答案
相关问题