我可以让Surefire仅执行一次昂贵的设置/拆卸吗? [英] Can I make Surefire perform expensive setup/teardown only once?

查看:89
本文介绍了我可以让Surefire仅执行一次昂贵的设置/拆卸吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列的单元测试,所有这些都需要与Apache Zookeeper服务器进行通信.显然,如果我有一个用于模拟服务器连接的库(或者一种简单的方式来滚动自己的库),那将是最佳选择,但据我所知,这时不存在任何库,并且我很犹豫地找到了足够多的活动部件手动尝试.

I have a series of unit tests that all need to talk to an Apache Zookeeper server. Obviously, if I had a library for mocking server connections (or an easy way to roll my own) that would be optimal, but as far as I can tell none exists at this point, and there's enough moving parts under the hood that I hesitate to try it by hand.

因此,到目前为止,我们的解决方案是在本地建立一个虚拟服务器,执行测试,最后将其拆除.这种工作,尽管据我所知,没有一种简单的方法可以告诉Surefire在整个测试运行中执行一次操作-充其量来说,我有@BeforeClass@AfterClass装饰.

So, our solution so far has been to stand up a dummy server locally, perform the tests, then tear it down at the end. This kind of works, though as far as I can tell there's no easy way to tell Surefire to do something once per entire test run -- at best, I have @BeforeClass and @AfterClass decorations.

Zookeeper的初始化过程将应该进行几毫秒的测试的时间变成每个类几秒钟,这对整个项目来说要花费几分钟.如果我可以设置测试,使它能够站立在服务器上,运行每个测试,然后将其拆除,那么我认为速度至少会提高一个数量级.

The Zookeeper initialization process is turning what should be several-millisecond test runs into several seconds per class, which works out to several minutes for the whole project. If I could set up the tests so that it stands up a server, runs each test, then tears it down, I think I'd see a speedup of at least an order of magnitude.

有简单的解决方法吗?我会以错误的方式处理吗?如果有现有的模拟动物园管理员库,或者有一种简单的方法可以轻松实现自己的目标,那也是一个很好的解决方案.

Is there a simple fix? Am I going about this the wrong way? If there's an existing mock-zookeeper library, or a simple way to roll my own, that's a fine solution too.

推荐答案

听起来像是集成测试.看一下故障保险"而不是surefire,并在附加生命周期阶段中进行昂贵的工作以进行集成测试的设置和拆除.

Sounds like an integration test. Look at 'failsafe' instead of surefire, and do the expensive stuff in the additional lifecycle phases for setup and teardown of integration tests.

这篇关于我可以让Surefire仅执行一次昂贵的设置/拆卸吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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