maven - maven测试前后如何运行
问题描述
mvn test
我希望在使用 maven test 执行所有测试用例之前初始化某些资源,并在执行所有测试用例后销毁它们。
我研究了 jUnit @BeforeClass、@AfterClass、@Before和@After,但它们都没有帮助。
我尝试使用 maven 生命周期阶段,即如下所示的预集成测试,但即使在这种情况下,预期的测试用例 (TestPostgresqlEmbedded) 也不会首先执行。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<executions>
<execution>
<id>test-init</id>
<configuration>
<runOrder>alphabetical</runOrder>
<includes>
<include>**/TestPostgresqlEmbedded.java</include>
</includes>
</configuration>
<phase>pre-integration-test</phase>
</execution>
<execution>
<id>test-all</id>
<configuration>
<runOrder>alphabetical</runOrder>
</configuration>
</execution>
</executions>
</plugin>
我怎样才能做到这一点?
解决方案
Use the integration-test
phase for tests with databases. Then you have pre-integration-test
to set up your database resources, and post-integration-test
to destroy them.
推荐阅读
- android - 为什么谷歌地图不会出现在颤振中?
- python - 如何用另一个参数中的字符串替换数组中的元素
- php - 分页记录编号
- java - 如何找到菜单栏在页面上可见 x 个选项卡
- javascript - 使用 setInterval 创建进度条
- maven - 如何将包控制器添加到使用 Netbeans 12 中的 FXML JavaFX Maven Archetype (Gluon) 创建的项目中?
- java - 如何在 Google App Engine 中缩小 HTML 响应
- php - 标题下方所有页面上的 Wordpress 错误(使用主题 elumine)
- python - 在 Jupyter Notebook 中使用 matplolib 无法正确显示图
- python - 使用 Python 和“scrape-linkedin”包抓取配置文件