title: How to use WireMock's response template in JUnit 5 Tests
body: <p>I'm trying to use the <a href="http://wiremock.org/docs/response-templating/" rel="noreferrer">Response Templating</a> feature of WireMock, but it does not seem to work with the sample piece of code provided in the docs.</p>
  
  <p>This is a sample piece of code:</p>
  
  <pre class="lang-java prettyprint-override"><code>
  import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
  import static com.github.tomakehurst.wiremock.client.WireMock.get;
  import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
  import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
  
  import com.github.tomakehurst.wiremock.WireMockServer;
  import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer;
  import com.github.tomakehurst.wiremock.junit.WireMockRule;
  import io.restassured.RestAssured;
  import org.hamcrest.Matchers;
  import org.junit.Rule;
  import org.junit.jupiter.api.AfterEach;
  import org.junit.jupiter.api.BeforeEach;
  import org.junit.jupiter.api.Test;
  
  public class WireMockTest {
  
    @Rule
    public WireMockRule wm = new WireMockRule(options()
        .extensions(new ResponseTemplateTransformer(true)));
    private WireMockServer wireMockServer;
  
    @BeforeEach
    public void setup() {
      this.wireMockServer = new WireMockServer(
          options().port(8081));
      this.wireMockServer.stubFor(get(urlEqualTo("/test-url"))
          .willReturn(aResponse()
              .withBody("{{request.url}}")
              .withTransformers("response-template")));
      this.wireMockServer.start();
    }
  
    @Test
    public void test() {
      RestAssured.when()
          .get("http://localhost:8081/test-url")
          .then()
          .log().ifError()
          .body(Matchers.equalTo("/test-url"));
    }
  
    @AfterEach
    public void tearDown() {
      wireMockServer.stop();
    }
  }
  
  </code></pre>
  
  <h3>Expected Output:</h3>
  
  <p>Tests should pass. (meaning the {{request.url}} should be substituted with <code>/test-url</code> as a result of template rendering).</p>
  
  <h3>Actual Output:</h3>
  
  <pre><code>....
  
  java.lang.AssertionError: 1 expectation failed.
  Response body doesn't match expectation.
  Expected: "/test-url"
    Actual: {{request.url}}
  
  </code></pre>
  
  <h3>Things I've tried:</h3>
  
  <ol>
  <li>Since these are test cases using JUnit 5 API, did not add <code>@Rule WireMockRule</code>, instead added the <code>.withTransformers("response-template")</code>.  </li>
  <li>Tried changing the test cases to use JUnit 4 API, and added</li>
  </ol>
  
  <pre class="lang-java prettyprint-override"><code>@Rule
  public WireMockRule wm = new WireMockRule(options()
      .extensions(new ResponseTemplateTransformer(false))
  );
  </code></pre>
  
  <p>(along with <code>withTransformers</code>)<br>
  3. Changed the <code>WireMockRule</code> to</p>
  
  <pre class="lang-java prettyprint-override"><code>@Rule
  public WireMockRule wm = new WireMockRule(options()
      .extensions(new ResponseTemplateTransformer(true))
  );
  </code></pre>
  
  <p>(along with withTransformers)<br>
  4. Removed the <code>withTransformers</code> only keeping the <code>WireMockRule</code>. (JUnit 4)<br>
  5. I've also tried the above combination with JUnit 5 API too.</p>
  
  <p>But none of the above variations worked. Is there anything that I'm missing?</p>