使用Thread Local的应用程序部分的单元测试 [英] Unit testing parts of the application that use Thread Local
本文介绍了使用Thread Local的应用程序部分的单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I am trying to implement unit testing in a web application and certain parts of it use ThreadLocal.
我不知道如何进行测试.
I cannot figure out how to go about testing it.
看起来Junit使用单个线程(即主线程)运行所有测试.
It looks like Junit runs all its tests using a single thread, namely the main thread.
我需要能够为ThreadLocal变量分配不同的值.
I need to be able to assign different values to my ThreadLocal variable.
有人遇到过这种情况吗?你们有什么建议?
Has anyone come across such a scenario ? What do you guys recommend.
推荐答案
我只是在单元测试中启动线程.
I would simply start threads within my unit test.
我建议您使用 Futures
并使用
I recommend you use Futures
and execute them using a ThreadPoolExecutor
.
这篇关于使用Thread Local的应用程序部分的单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文