이 같은 Gradle을 통해 포함 할 수 Simple Framework를 사용 :
public class HttpMockingTest {
class TestContainer implements Container {
int n = 0;
@Override
public void handle(Request req, Response resp) {
// count
n += 1;
// close the response
try {
resp.getOutputStream().close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
@Test
public void test0() throws IOException {
// this sets up the server
TestContainer testContainer = new TestContainer();
Server server = new ContainerServer(testContainer);
SocketConnection socketConnection = new SocketConnection(server);
InetSocketAddress inetSocketAddress = new InetSocketAddress("localhost", 9999);
socketConnection.connect(inetSocketAddress);
// this invokes the server
int n = 2;
for (int i = 0; i < n; i++) {
try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
CloseableHttpResponse httpResponse = httpClient.execute(new HttpGet("http://localhost:9999/foo"));
}
}
// make assertions
assertEquals(n, testContainer.n);
}
}
:
testCompile 'org.simpleframework:simple:5.+'
당신은이 같은 테스트 케이스를 작성할 수
출처
2017-10-13 01:44:52
Rob