参数化 jUnit 测试,无需更改 runner
是否有一种干净的方法来运行参数化 jUnit 4 测试而不更改运行器,即不使用 @RunWith(Parameterized.class)
?
我的单元测试已经需要一个特殊的运行程序,并且我无法用参数化
替换这个运行程序。也许有某种“跑步者链接”,所以我可以同时跑步? (只是一个疯狂的猜测......)
Is there a clean way to run parameterized jUnit 4 tests without changing the runner, i.e. without using@RunWith(Parameterized.class)
?
I have unit tests which require a special runner already and I can't replace this one with Parameterized
. Maybe there is some kind of "runner chaining" so I could both runners at the same time? (Just a wild guess...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发布了一个包含几个运行程序的框架,这些运行程序能够在测试类上强制参数化,同时允许您链接任意第 3 方运行程序以进行实际的测试执行。
框架是 CallbackParams - (http://callbackparams.org) - 这些是运行器:
通过使用框架注释 ...
... 您可以通过以下方式指定任意第 3 方运行器:
参数化然而,使用 CallbackParams 的测试与传统的测试参数化方法有很大不同。这篇教程文章中解释了原因,BddRunner 解释了教程文章末尾处。
对于您的第一个 CallbackParams 测试,您可能更喜欢 BddRunner,因为它需要较少的样板文件,但是当您开始在不同测试类之间重用参数值时,您可能最好使用 CallbackParamsRunner,它需要更强的类型检查。
另外 - 使用 BddRunner 你不能有任何 @Test-methods。相反,您必须使用框架注释@Given、@When 和@Then。该要求有时会与第三方运行程序的要求发生冲突,但通常效果很好。
祝你好运!
I have released a framework with a couple of runners that are able to enforce parameterization on the test-class while allowing you to chain an arbitrary 3rd-party runner for the actual test-execution.
The framework is CallbackParams - (http://callbackparams.org) - and these are the runners:
By using the framework annotation ...
... you can specify an arbitrary 3rd-party runner in this manner:
Parameterized tests with CallbackParams differ considerably from the traditional approach to test-parameterization, however. The reasons are explained in this tutorial article with BddRunner explained near the end of the tutorial article.
For your first CallbackParams test you would probably prefer BddRunner, since it requires less boiler-plate stuff, but when you start reusing parameter values between different test-classes you are probably better off with CallbackParamsRunner, which demands stronger type-checking.
Also - with BddRunner you must not have any @Test-methods. Instead you must use the framework annotations @Given, @When and @Then. That requirement sometimes clash with those of the third-party runner but it usually works out quite well.
Good Luck!
org.junit.runners.Parameterized
是由org.junit.internal.builders.AnnotatedBuilder
通过反射机制创建的。也许您可以将Parameterized
扩展为您自己的 Runner:@RunWith(MyParameterized.class)。org.junit.runners.Parameterized
is created byorg.junit.internal.builders.AnnotatedBuilder
by reflect mechanism. Maybe you could extendParameterized
as your own Runner: @RunWith(MyParameterized.class).