Java 在使用tempus fugit和junit时,如何定义线程数?

Java 在使用tempus fugit和junit时,如何定义线程数?,java,concurrency,junit,webdriver,Java,Concurrency,Junit,Webdriver,我使用它是为了并行执行junit测试。我的测试类包含多个WebDriver junit测试(>20),每个测试持续时间超过20-40秒 这就是问题所在: import com.google.code.tempusfugit.concurrency.ConcurrentTestRunner; @RunWith(ConcurrentTestRunner.class) public class TestClass{ @Test public void test1(){

我使用它是为了并行执行junit测试。我的测试类包含多个WebDriver junit测试(>20),每个测试持续时间超过20-40秒

这就是问题所在:

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
    }
}
当我的测试同时触发时,会创建20多个firefox会话,而我们的系统没有资源来处理这些会话

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

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
    }
}
在使用fugit的ConcurrentTestRunner.class runner时,我想以某种方式限制线程数,以便每次只有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库的文档没有说明如何限制线程数,但我猜这是可行的


提前感谢。

您可以将
@Concurrent
ConcurrentTestRunner
结合使用,以限制线程数

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

看看细节

使用它,比如

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

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

    @Test
    public void test1() {
        // ...
    }
}
@RunWith(ConcurrentTestRunner.class)
@并发(计数=5)
公共类ConcurrentTestRunnerTest{
私有静态最终集线程=synchronizedSet(newhashset());
@试验
公共void test1(){
// ...
}
}

注意事项:我把这个弯进去了,这样你的里程数可能会有所不同,让我知道你进展如何

您可以将
@Concurrent
ConcurrentTestRunner
组合使用,以限制线程数

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

看看细节

使用它,比如

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

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

    @Test
    public void test1() {
        // ...
    }
}
@RunWith(ConcurrentTestRunner.class)
@并发(计数=5)
公共类ConcurrentTestRunnerTest{
私有静态最终集线程=synchronizedSet(newhashset());
@试验
公共void test1(){
// ...
}
}

注意事项:我把这个弯进去了,这样你的里程数可能会有所不同,让我知道你进展如何

托比,它似乎工作得很好。请允许我感谢您的直接和有益的回应。不幸的是,我的名声不允许我投票。托比,这似乎很有效。请允许我感谢您的直接和有益的回应。不幸的是,我的名声不允许我投票。