For my application I created my own type of ApplicationContext
that allows me to interact in specific manners that are needed for may application.
(对于我的应用程序,我创建了自己的ApplicationContext
类型,该类型允许我以可能需要应用程序的特定方式进行交互。)
(由于该应用程序是桌面应用程序,因此我将创建如下上下文:)
@SpringBootApplication
@Import(StandaloneConfiguration.class)
@PropertySource(value = {"application.properties", "server.properties"})
public class OpenPatricianApplication extends Application {
private ApplicationContext context;
@Override
public void init() {
SpringApplicationBuilder builder = new SpringApplicationBuilder(OpenPatricianApplication.class);
context = builder.contextClass(DependentAnnotationConfigApplicationContext.class).run(getParameters().getRaw().toArray(new String[0]));
// more initialisation
}
}
}
Now I want to create a Spring Boot integration test that actually relies on the functionality of my own ApplicationConext
implementation.
(现在,我想创建一个实际上依赖于我自己的ApplicationConext
实现的功能的Spring Boot集成测试。)
@SpringBootTest(classes = {ServerTestConfiguration.class})
public class ServerIntegrationTest {
private DependentAnnotationConfigApplicationContext context;
}
How do I go about initializing my context
in the test?
(如何在测试中初始化我的context
?)
context
must be created in order to start the spring application for this to work, but with the SpringBootTest
annotation this already happened, when the constructor is entered. (必须创建context
才能启动spring应用程序才能SpringBootTest
正常工作,但是使用SpringBootTest
批注时,在输入构造函数时已经发生了这种情况。)
(现有的注释或参数是否可以应用?)
Should tests of these nature not be annotated withSpringBootTest
at all and the application created manually? (应该不使用SpringBootTest
完全注释这些性质的测试,而是手动创建应用程序吗?)