I have a docker DB setup method, which currently located in @BeforeAll
.
Currently, Construct as below
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public DockerConstructorTest{
@BeforeAll
public static void setup(){
...
CreateContainer
...
}
@AfterAll
public static void done(){
...
Stop & Remove Container
...
}
}
There're multiple test classes which all extends this Test super class, each test class will construct one container and remove it after it is done. Therefore, maven consumes a lot time to manage docker. (Creation and Removal)
My question is that whether there's better way to deal with it
The ideal case what I may want to achieve is that this container create & deletion only run once as before @SpringBootTest starts, it will be shared with all test classes. In the meanwhile, it would not stop other developer creating new container for some corner scenarios as well.
I have some incomplete idea:
- Add Constructor trigger within SpringBoot main class, if it is started by Test, run Docker container constructor. But it also means that I add some test related code in Main Class, making them coupled. Personally hate this happens
- Override SpringBootTest. Overriding bugs me that whether I should do.
Please share your brilliant ideas, I will be appreciated if it would solve this issue, or partial of this issue.