亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 HTTP 客戶端 apache 上編寫測試?

如何在 HTTP 客戶端 apache 上編寫測試?

UYOU 2022-06-30 18:12:35
我正在嘗試為我的服務編寫一個測試,該測試與另一個從數據庫返回項目的服務建立連接。我的問題是我在測試中設置了連接屬性并啟動了服務。這怎么可能是模擬或類似的?我的啟動服務方法:public void doStartService() {        super.doStartService();        PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager();        manager.setDefaultMaxPerRoute(maxConnectionsPerRoute);        manager.setMaxTotal(maxConnections);        RequestConfig requestConfig = RequestConfig.custom()                .setConnectTimeout(connectTimeout)                .setSocketTimeout(socketTimeout)                .setRedirectsEnabled(false).build();        HttpClientBuilder builder = HttpClientBuilder.create();        builder.setDefaultRequestConfig(requestConfig);        builder.setConnectionManager(manager);        client = builder.build();    }我的設置測試方法和一種測試方法:private ProductCatalogIntegrationService service; @Before    public void setup() {        service = new Service();        service.setConnectTimeout(10000);        service.setSocketTimeout(10000);        service.setMaxConnections(10);        service.setMaxConnectionsPerRoute(10);        service.setUrl("http://localhost:8888/products");        service.doStartService();    }    @Test    public void testReturnProductById() {        service.setProductById(GET_PRODUCT_BY_ID); // set url from get product by id, by this url my other service goes to the database        jsonItem = service.getProductById("1"); //get product by id 1        assertEquals(jsonItem.getId(), FIRST_PRODUCT_ID); // I compare the id on which I made the request to the database, so that I came and was wrapped in a class wrapper    }如何正確執行,以免在測試中配置連接?
查看完整描述

1 回答

?
Qyouu

TA貢獻1786條經驗 獲得超11個贊

Javalin將是模擬真實服務的絕佳工具,因為它允許在測試中進行狀態斷言。

也可以使用Wiremock 。但這會導致難以維護行為測試(驗證)。


查看完整回答
反對 回復 2022-06-30
  • 1 回答
  • 0 關注
  • 167 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號