zoukankan      html  css  js  c++  java
  • 【转】Debugging WireMock calls when using JUnit WireMockRule

    From: https://technicaltesting.wordpress.com/2016/04/29/debugging-wiremock-calls-when-using-junit-wiremockrule/

    Mocking using the WireMockRule in your JUnit test classes and struggle with 404’s?

    It is not that trivial to find in the WireMock documentation but it is in there, under ‘Listening for requests’ @ http://wiremock.org/verifying.html. Plain debugging fine, but sometimes one really wants to know the details of the calls made to the underlying services that are consumed, especially when WireMocking these services and there is a fine grained matching mechanism to deal with.

    Below is the quick awesome tip to get the details you need to resolve the WireMock returned 404’s easily.

    Add a request listener to your WireMockRule and Use Java 8 lambdas to smoothly implement the WireMock interface RequestListener that has the single method requestReceived(Request request, Response response). Print out the reponse and request details you want. Run your tests and check the print outs, all set!

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    import com.github.tomakehurst.wiremock.junit.WireMockRule;
     
    public class Test {
     
       @Rule
       public WireMockRule wireMockRule = new WireMockRule(6969);
     
       @Before
       public void setupTest() {
          wireMockRule.addMockServiceRequestListener((request, response) -> {
             System.out.println("URL Requested => " + request.getAbsoluteUrl());
             System.out.println("Request Body => " + request.getBodyAsString());
             System.out.println("Request Headers => " + request.getAllHeaderKeys());
             System.out.println("Response Status => " + response.getStatus());
             System.out.println("Response Body => " + response.getBodyAsString());
          });
       }
       ...
    }
  • 相关阅读:
    javascript类型系统——日期Date对象
    javascript类型系统——undefined和null
    javascript运算符语法概述
    javascript运算符
    javascript语句——表达式语句、块语句、空语句和声明语句
    javascript语句
    javascript中的数据类型转换
    javascript类型系统
    Sqli-labs Less-21 cookie注入 base64编码 updatexml()报错注入
    Sqli-labs Less-20 cookie注入 extractvalue()报错注入
  • 原文地址:https://www.cnblogs.com/z1500592/p/9441113.html
Copyright © 2011-2022 走看看