【发布时间】:2014-11-25 18:11:05
【问题描述】:
我想知道您通常如何为集成测试设置数据。
当我的测试开始时,我启动嵌入式码头:
@Before
public void startServer() throws Exception {
server = new Server(8080);
server.setStopAtShutdown(true);
WebAppContext webAppContext = new WebAppContext();
webAppContext.setDescriptor("WEB-INF/embedded-web.xml");
webAppContext.setContextPath("/core-test");
webAppContext.setResourceBase("src/main/webapp");
webAppContext.setClassLoader(getClass().getClassLoader());
server.addHandler(webAppContext);
server.start();
}
在embedded-web.xml中有一个spring应用上下文的引用:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext-test.xml</param-value>
</context-param>
在 applicationContext-test.xml 中有一个内存 h2 数据库的配置:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.h2.Driver" />
<property name="url" value="jdbc:h2:mem:test;DB_CLOSE_DELAY=-1" />
</bean>
最好的解决方案是将 Spring 服务类自动连接到测试中,然后设置数据库,但我想访问由 jetty 启动的应用程序上下文是不可能的。
【问题讨论】:
标签: java spring junit integration-testing embedded-jetty