【发布时间】:2017-12-04 14:09:28
【问题描述】:
我有基于 maven 的 J2EE 项目。该项目包含通过resources.xml 和persistence.xml 建立的数据库连接。连接可以正常部署。
我的问题是,我想运行嵌入式 TomEE 服务器进行集成测试。对于这些测试,我需要使用内存数据库。
要启动 TomEE,我使用了如下所示的 maven 插件组合。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.13</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.tomee.maven</groupId>
<artifactId>tomee-maven-plugin</artifactId>
<version>7.0.4</version>
<executions>
<execution>
<id>start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<checkStarted>true</checkStarted>
</configuration>
</execution>
<execution>
<id>stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<simpleLog>true</simpleLog>
</configuration>
</plugin>
当我启动 maven 目标 mvn install 时,服务器按预期运行,但数据库连接错误。我没有找到方法,如何设置,我需要使用 src/test/resources 而不是 src/main/resources。
你知道如何设置这个插件吗?我愿意接受类似解决方案的建议,这些解决方案很简单,不包含“很多”框架。
提前谢谢你。
【问题讨论】:
标签: java maven integration-testing