我正在使用tempus-fugit为了并行执行junit测试。我的测试类包含多个 WebDriver junit 测试 (>20),每个测试持续超过 20-40 秒。
这就是问题:
当我的测试同时触发时,会创建超过 20 个 Firefox session ,而我们的系统没有资源来处理这个问题!
这就是我想要实现的目标:
我想在使用 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 库的文档没有说明如何限制线程数,但我猜这是可行的!
提前谢谢您。
最佳答案
您可以将@Concurrent
与ConcurrentTestRunner
结合使用来限制线程数量。
它可以在 Github 上获取,我已将快照版本 (1.2 #3) 推送到 Sonatype .
看看at the commit on Github了解详情。
使用类似的东西
@RunWith(ConcurrentTestRunner.class)
@Concurrent(count = 5)
public class ConcurrentTestRunnerTest {
private static final Set<String> threads = synchronizedSet(new HashSet<String>());
@Test
public void test1() {
// ...
}
}
警告:我对此进行了弯曲,因此您的里程可能会有所不同,请让我知道您的进展情况!
关于java - 使用 tempus-fugit 和 junit 时如何定义线程数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19009104/