title: Unit Testing - Wiremock verify failing with connection error
body: <p>I'm testing a spring-boot application and using wiremock stubs to mock external API. In one test case I want to make sure that my stub gets called exactly once but it's failing with connection error.</p>
  
  <p>My Test File:</p>
  
  <pre><code>@SpringBootTest
  @AutoConfigureWebTestClient
  @ActiveProfiles("test")
  class ControllerTest {
  
      @Autowired
      private lateinit var webClient: WebTestClient
  
      private lateinit var wireMockServer: WireMockServer
  
      @BeforeEach
      fun setup() {
          wireMockServer = WireMockServer(8081)
          wireMockServer.start()
          setupStub()
      }
  
      @AfterEach
      fun teardown() {
          wireMockServer.stop()
      }
  
      // Stub for external API
      private fun setupStub() {
          wireMockServer.stubFor(
          WireMock.delete(WireMock.urlEqualTo("/externalApiUrl"))
              .willReturn(
                  WireMock.aResponse()
                      .withHeader("Content-Type", "application/json")
                      .withStatus(204)
                      .withBodyFile("file.json")
              )
      )
      }
  
      @Test
      fun test_1() {
  
          val email = "some-email"
          val Id = 123
  
          webClient.post()
          .uri { builder -&gt;
              builder.path("/applicationUrl")
                  .queryParam("email", email)
                  .queryParam("id", Id)
                  .build()
          }
          .exchange()
          .expectStatus().isOk
  
          WireMock.verify(exactly(1), WireMock.deleteRequestedFor(WireMock.urlEqualTo("/externalApiUrl")))
  }
  </code></pre>
  
  <p>When I run this test I'm getting the following error:</p>
  
  <blockquote>
    <p>org.apache.http.conn.HttpHostConnectException: Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)</p>
  </blockquote>
  
  <p>Please let me know where I'm doing wrong. Thanks in advance.</p>