如何在SureFire测试阶段之前和之后执行脚本 [英] How to execute scripts before and after SureFire test phase

查看:95
本文介绍了如何在SureFire测试阶段之前和之后执行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调用mvm test时,我想在调用Surefire JUnit之前执行setup.sql脚本,然后在之后执行teardown.sql脚本.

When I invoke mvm test, I want to execute a setup.sql script before Surefire JUnit is invoked and then execute a teardown.sql script after.

我从知道像这样的问题如何在测试阶段执行脚本,但是我不知道如何定义事件的这种特定顺序.谢谢!

I know from questions like this how to execute scripts during the test phase, but I have no idea how to define this specific sequence of events. Thank you!

推荐答案

不是使用surefire插件,而是使用它的同级failsafe插件.他们都执行测试,但是处于不同的生命周期阶段.测试中的surefire插件和集成测试中的failsafe插件.请参见生命周期阶段和<一个href ="https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Built-in_Lifecycle_Bindings" rel ="nofollow noreferrer">默认插件绑定.

Not with the surefire plugin but with its sibling the failsafe plugin. They both execute Tests but in different life-cycle phases. The surefire plugin in test and the failsafe plugin in integration-test. See life-cycle phases and the default plugin bindings.

在集成测试阶段运行故障安全插件的优点在于,它具有前阶段和后阶段.

The advantage of the failsafe plugin running in the integration test phase is that there are pre- and post- phases.

由于您提到了一些sql脚本,因此您似乎想准备一个数据库.那时,您实际上不再进行单元测试,而是编写集成测试.因此,在这里使用故障保护插件最有意义.

Since you mention some sql script it seems you want to prepare a database. At that point you are not really doing unit testing anymore but writing an integration test. So using the failsafe plugin makes the most sense here.

这篇关于如何在SureFire测试阶段之前和之后执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆