开发者

Is there any *real* solution for taking advantage of multiple cores when running a JUnit/TestNG test suite?

I know support exists for running JUnit or TestNG test suites in parallel, but it requires specific configuration (such as specifying threa开发者_如何学JAVAd counts, for example) and most importantly do not prevent race conditions in non-thread-safe code.

Are there any tools for the JVM which transparently (ie, without explicit configuration) allocate individual tests to different CPU cores (using different threads in the same process or different processes), while preventing race conditions regardless of thread-safety?

If no such tool exists, what would be the best approach to implement one?


My strong suggestion would be to run your tests concurrently with the usual JUnit / TestNG tools.

The reason is simple: If a test fails due a race condition, then the test has done it's job perfectly - it has identified a bug in your design, code or concurrency assumptions that you should fix.

Anything that is non-thread-safe that is used simultaneously by multiple test threads (e.g. a mutable static singleton object that is being used on a global basis) is probably a design flaw - you should either make it thread safe or initialise it separately each time as a local object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜