简体   繁体   English

使用ClasspathSuite进行参数化测试

[英]Parameterized test with ClasspathSuite

I need to run my test multiple times in succession (4 times, one for each browser I am testing with WebDriver). 我需要连续运行我的测试多次(4次,对于我正在使用WebDriver测试的每个浏览器一次)。 I understand that this is a use case for parameterized tests. 我了解这是参数化测试的用例。 However, I am utilizing ClasspathSuite and so it seems I cannot specify multiple @RunWith annotations. 但是,我正在使用ClasspathSuite ,因此似乎无法指定多个@RunWith批注。

Is there any way I can get my test to run multiple times and send some sort of parameter (like 0 - 3 for the 4 runs I need) to the test? 有什么办法可以让我的测试多次运行并将某种参数(例如0-3代表我需要的4次运行)发送给测试?

I just faced this, ClasspathSuite handles this just fine. 我只是面对这个问题, ClasspathSuite可以很好地处理这个问题。 The trick is to use these annotations in the little dummy project that finds & launches tests (across other projects): 诀窍是在用于查找和启动测试的小虚拟项目(在其他项目中)中使用这些注释:

@RunWith(ClasspathSuite.class)
@SuiteTypes(RUN_WITH_CLASSES)

Then any test requiring a specific runner just uses that runner directly, such as @RunWith(Parameterized.class) 然后,任何需要特定运行程序的测试都将直接使用该运行程序,例如@RunWith(Parameterized.class)

See section "Running other RunWith-Suites" here: https://github.com/takari/takari-cpsuite 请参见此处的“运行其他RunWith-Suites”部分https : //github.com/takari/takari-cpsuite

Due to a wide range of tests, I opted to use all options: 由于测试范围广泛,我选择使用所有选项:

@SuiteTypes({RUN_WITH_CLASSES, TEST_CLASSES, JUNIT38_TEST_CLASSES})

(The default appears to be just TEST_CLASSES.) (默认值似乎只是TEST_CLASSES。)

解决方案:我对每个测试用例进行了相同的参数设置(使用Eclipse中的replace方法将相同的代码添加到每个测试用例中。然后,我设置了代码清理和格式,因此当我运行它们时,它将代码恢复为漂亮的状态(因为我的插入内容全部在一行上)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM