并发JUnit测试 [英] Concurrent JUnit testing

查看:145
本文介绍了并发JUnit测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大的JUnit测试套件,其中我很想同时运行所有的测试有两个原因:

I have a large JUnit test suite, where I'd quite like to run all the tests concurrently for two reasons:


  • 多个核心可以更快地运行整个测试套件

  • 希望检测到由于非线程安全的全局对象而导致的一些错误

我认识到这将迫使我重构一些代码,使它线程安全,但我认为这是一件好事: - )

I recognise that this will force me to refactor some code to make it thread-safe, but I consider that to be a good thing :-)

推荐答案

您是否已修复JUnit? TestNG 提供了开箱即用的多线程测试,它与JUnit测试兼容(您需要进行一些更改)。例如,您可以运行这样的测试:

Are you fixed to JUnit? TestNG provides good multi thread testing out of the box and it's compatible with JUnit tests (you need to make a few changes). For example you could run a test like this:

@Test(threadPoolSize = 3, invocationCount = 9,  timeOut = 10000)
public void doSomething() {
...
}

这意味着 doSomething()方法将被3个不同的线程调用9次。

This would mean that the doSomething() method will be invoked 9 times by 3 different threads.

TestNG

这篇关于并发JUnit测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆