0
假設我有一個抽象類,稱爲AbstractTestWithNetwork
規則:「沒有這樣的網絡」的錯誤嘗試的時候重新使用Testcontainers與網絡從抽象類
@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"}