0

我正在使用tempus-fugit来并行执行 junit 测试。我的测试类包含多个 WebDriver junit 测试(>20),每个测试持续超过 20-40 秒。

这就是问题:

当我的测试同时触发时,会创建 20 多个 firefox 会话,而我们的系统没有资源来处理它!

这就是我想要实现的目标:

我想以某种方式限制使用 fugit 的 ConcurrentTestRunner.class 运行器时的线程数,以便每次只有 3-4 个测试并行运行。我知道我可以通过从 JUnit 迁移到 TestNG 来实现这一点,但出于多种原因,这不是一个选择!

这是我的测试类的外观:

import com.google.code.tempusfugit.concurrency.ConcurrentTestRunner;

@RunWith(ConcurrentTestRunner.class)
public class TestClass{
    @Test
    public void test1(){
        // Do something with Selenium WebDriver
    }

    // ...
    // More Tests
    // ...

    @Test
    public void test20(){
        // Do something with Selenium WebDriver
    }
}

欢迎任何建议。不幸的是, tempus-fugit 库的文档没有说明有人如何限制线程数,但我猜这是可行的!

先感谢您。

4

1 回答 1

3

您可以结合@ConcurrentwithConcurrentTestRunner来限制线程数。

它在 Github 上可用,我已将快照版本 (1.2 #3) 推送到Sonatype

详细信息请查看Github 上的提交

使用它像

@RunWith(ConcurrentTestRunner.class)
@Concurrent(count = 5)
public class ConcurrentTestRunnerTest {

    private static final Set<String> threads = synchronizedSet(new HashSet<String>());

    @Test
    public void test1() {
        // ...
    }
}

警告:我弯了这个,所以你的里程可能会有所不同,让我知道你的进展!

于 2013-09-25T17:47:03.873 回答