Java Dropwizard 1.0集成测试:使用外部API
我试图找出如何集成外部API,并针对它运行每个集成测试。我一直在阅读和研究:Java Dropwizard 1.0集成测试:使用外部API,java,api,unit-testing,integration,dropwizard,Java,Api,Unit Testing,Integration,Dropwizard,我试图找出如何集成外部API,并针对它运行每个集成测试。我一直在阅读和研究: 但看起来这些是测试本地端点的示例,而不是外部端点。我希望能够使用JUnit测试来测试我的api调用。目前,我必须启动并运行我的应用程序,以确保它们正常工作 这是我目前正在探索的方向: private Client client; @Before public void setUp() throws Exception { client = ClientBuilder.newClient(); } @
private Client client;
@Before
public void setUp() throws Exception {
client = ClientBuilder.newClient();
}
@After
public void tearDown() throws Exception {
client.close();
}
@Test
public void testHitApi() throws Exception {
client.target("https://api.github.com/users/" + getUser() + "/repos");
}
任何帮助都将不胜感激,谢谢 您需要进行api调用以命中端点 只做:
client.target("https://api.github.com/users/" + getUser() + "/repos")
返回一个WebTarget
理想情况下,你应该做以下事情:
client
.target("https://api.github.com/users/" + getUser() + "/repos")
.request()
.get() ; // for a get call
谷歌搜索准确的post/put/delete呼叫 如果您打算针对外部api或单独运行的api实例运行集成测试
testEnvironment = new Environment("Test environment", Jackson.newObjectMapper(),
null, new MetricRegistry(), null);
ObjectMapper mapper = Jackson.newObjectMapper(new YAMLFactory());
IntegrationTestConfiguration integrationTestConfiguration = mapper.readValue(fixture("integration-testing-config.yml"),
IntegrationTestConfiguration.class);
将您的客户机实例化为
exampleClient = new exampleClient(testEnvironment, clientConfiguration);
希望这能有所帮助。嗨,我是否正确理解-您想测试您构建的资源?您应该阅读:它描述了如何利用您的资源加速单元测试,然后您可以点击它。