I am trying to test my rest interface with a class that inherits from JerseyTest. While the first test method succeeds without any problem, the following tests fail with an bind exception Address already in use. Do I need to release some kind of resource in between the tests to get this running?
class MyClass extends JerseyTest () {
@Override
protected Application configure() {
return new ResourceConfig(MyClass.class);
}
@Test
testFirstThing() {
// test some request
}
@Test
testFirstThing() {
// test another request
}
}
I had the same issue today, some of the tests passed, but some failed with BindException
There is a solution in Jersey Test documentation: https://jersey.java.net/documentation/latest/test-framework.html#parallel
For a purpose of running multiple test containers in parallel you need to set the TestProperties.CONTAINER_PORT to 0 value. This will tell Jersey Test Framework (and the underlying test container) to use the first available port.
@Override
protected Application configure() {
forceSet(TestProperties.CONTAINER_PORT, "0");
return new ResourceConfig(MyClass.class);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With