假设我有一个名为的抽象类AbstractTestWithNetwork
:
@RunWith(JUnit4.class)
public abstract class AbstractTestWithNetwork {
@ClassRule
public static Network network = Network.newNetwork();
@ClassRule
public static GenericContainer etcd = new GenericContainer<>("alpine:3.6")
.withNetwork(network);
}
我想通过扩展它来简单地重新使用它以在多个类中拥有相同的容器:
public class FirstTestClass extends AbstractTestWithNetwork {
@Test
public void emptyMethod() throws Exception {
System.out.println("An empty test method");
}
}
还有SecondTestClass
一个内容相同的。
我可以从 IDE 单独运行每个类,它们会通过。但是当我gradle test
从 IDE 运行或选择带有测试类的整个包时,只有第一个测试类通过。第二个我得到:
org.testcontainers.containers.ContainerLaunchException: Container startup failed
Caused by:
org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
Caused by:
org.testcontainers.containers.ContainerLaunchException: Could not create/start container
Caused by:
java.lang.reflect.UndeclaredThrowableException
Caused by:
java.lang.reflect.InvocationTargetException
Caused by:com.github.dockerjava.api.exception.NotFoundException: {"message":"No such network: a48cf082ab42a55c843e9963c3938f44dd93cceae09e1724d4fefd5b45f235f1"}