检查正在运行的代码是否是单元测试用例 [英] Check if the running code is unit test case or not
本文介绍了检查正在运行的代码是否是单元测试用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查正在运行的代码是否是单元测试用例或不为结果执行不同的代码,例如:
I want to check if the running code is unit tese case or not execute different code for the result such as:
if ( unit test case is running )
{
do something
}
else
{
do other thing
}
对此有什么想法吗?
推荐答案
这是一种糟糕的方法,您应该尝试通过 Mock 对象或其他机制来模拟您试图通过此语句避免的逻辑部分.
This is a bad approach you should try to simulate logic parts which you are trying to avoid by this statemetn through Mock ojects or other mechanism.
现在对于您的问题,您可以使用像 isUnittest
这样的 olean 变量,您可以在测试设置和拆卸时设置该变量,但正如我所说,我不建议您这样做.
Now to your question you can use a oolean variable like isUnittest
which you set on test setup and Teardown, ut as saied i dont recommend you doing this.
这篇关于检查正在运行的代码是否是单元测试用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文