У меня есть интеграционные тесты (cucumber), в которых я использую сервер Wiremock с портом 8085, и когда я запускаю класс выполнения теста, все работает, я добавляю другой класс для тестирования сервиса, в котором я использую другой экземпляр сервера WirkeMock с тем же порт успешно работает.
@RunWith(SpringRunner.class)
@SpringBootTest
public class ClasseCucumber {
private WireMockRule wiremockRule = new WireMockRule(8085);
@Before
public void beforeScenario() throws IOException {
wiremockRule.start();
WireMock.configureFor("localhost", wiremockRule.port());
stubFor(post(urlEqualTo(endpoint))
.withRequestBody(equalToJson(requete))
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBody(response)
.withStatus(HttpStatus.OK.value())));
}
@After
public void afterScenario() {
wiremockRule.stop();
}
}
@RunWith(SpringRunner.class)
@SpringBootTest
public class ServiceTest {
private static WireMockRule wiremock = new WireMockRule(8085);
@BeforeClass
public static void setUp() throws IOException {
wiremock.start();
WireMock.configureFor("localhost", wiremock.port());
stubFor(post(urlEqualTo(endpoint))
.withRequestBody(equalToJson(requete))
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBody(response)
.withStatus(HttpStatus.OK.value())));
}
@AfterClass
public static void afterTest() {
wiremock.stop();
}
@Test
public void appelTest() {
[...]
}
}
Моя проблема, когда я делаю чистую установку mvn (которая запускает все тесты) У меня появляется эта ошибка:
om.github.tomakehurst.wiremock.common.FatalStartupException: java.lang.RuntimeException: java.net.BindException: Адрес для использования
на com.github.tomakehurst.wiremock.WireMockServer.start (WireMockServer.java:147)
по адресу fr.pe.rind.service.da058.certification.web.CertificationStepdefs.beforeScenario (CertificationStepdefs.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (собственный метод)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
в java.lang.reflect.Method.invoke (Method.java:498)
в cucumber.runtime.Utils $ 1.call (Utils.java:32)
в cucumber.runtime.Timeout.timeout (Timeout.java:16)
в cucumber.runtime.Utils.invoke (Utils.java:26)
в cucumber.runtime.java.JavaHookDefinition.execute (JavaHookDefinition.java:60)
в cucumber.runtime.HookDefinitionMatch.runStep (HookDefinitionMatch.java:17)
в cucumber.runner.UnskipableStep.executeStep (UnskipableStep.java:22)
на cucumber.api.TestStep.run (TestStep.java:83)
в cucumber.api.TestCase.run (TestCase.java:58)
в cucumber.runner.Runner.runPickle (Runner.java:80)
at cucumber.runtime.junit.PickleRunners $ NoStepDescription.run (PickleRunners.java:140)
в cucumber.runtime.junit.FeatureRunner.runChild (FeatureRunner.java:68)
в cucumber.runtime.junit.FeatureRunner.runChild (FeatureRunner.java:23)
в org.junit.runners.ParentRunner $ 3.run (ParentRunner.java:290)
в org.junit.runners.ParentRunner $ 1.schedule (ParentRunner.java:71)
в org.junit.runners.ParentRunner.runChildren (ParentRunner.java:288)
в org.junit.runners.ParentRunner.access $ 000 (ParentRunner.java:58)
в org.junit.runners.ParentRunner $ 2.evaluate (ParentRunner.java:268)
в org.junit.runners.ParentRunner.run (ParentRunner.java:363)
в cucumber.runtime.junit.FeatureRunner.run (FeatureRunner.java:73)
в cucumber.api.junit.Cucumber.runChild (Cucumber.java:117)
в cucumber.api.junit.Cucumber.runChild (Cucumber.java:55)
в org.junit.runners.ParentRunner $ 3.run (ParentRunner.java:290)
в org.junit.runners.ParentRunner $ 1.schedule (ParentRunner.java:71)
в org.junit.runners.ParentRunner.runChildren (ParentRunner.java:288)
в org.junit.runners.ParentRunner.access $ 000 (ParentRunner.java:58)
в org.junit.runners.ParentRunner $ 2.evaluate (ParentRunner.java:268)
в cucumber.api.junit.Cucumber $ 1.evaluate (Cucumber.java:126)
в org.junit.runners.ParentRunner.run (ParentRunner.java:363)
в org.apache.maven.surefire.junit4.JUnit4Provider.execute (JUnit4Provider.java:365)
в org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun (JUnit4Provider.java:273)
в org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet (JUnit4Provider.java:238)
в org.apache.maven.surefire.junit4.JUnit4Provider.invoke (JUnit4Provider.java:159)
в org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader (ForkedBooter.java:383)
в org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess (ForkedBooter.java:344)
в org.apache.maven.surefire.booter.ForkedBooter.execute (ForkedBooter.java:125)
в org.apache.maven.surefire.booter.ForkedBooter.main (ForkedBooter.java:417)
Вызвано: java.lang.RuntimeException: java.net.BindException: Адрес для использования
на com.github.tomakehurst.wiremock.jetty9.JettyHttpServer.start (JettyHttpServer.java:165)
на com.github.tomakehurst.wiremock.WireMockServer.start (WireMockServer.java:145)