正确的使用方法是什么Assert.Inconclusive
and IgnoreAttribute
在 MS 单元测试框架中?
我们正在使用Assert.Inconclusive
主要用于测试:
- 尚未实施
- 不知何故损坏或不完整=需要进一步关注
- 当测试主体因任何原因被注释掉时
我们这样做是因为:
- 不确定的测试可以留言
- 我们希望在 TFS 的测试结果中看到这样的测试
我们的问题是Inconclusive
测试在 TFS 和 Resharper 中都被标记为错误。如果我们使用IgnoreAttribute
相反,我们将在 Resharper 中看到这些测试,但 MS 测试运行器和 TFS 将根本忽略它们。使用IgnoreAttribute
在 TFS 和 MS Test runner 中,就像评论整个测试一样,这是无用的。
我还看到当前实施中的困境。
-
Inconclusive
断言包含在 TRX 报告中,但 mstest.exe(以及 vstest.console.exe)将返回1
(意义error) 执行后。
- 测试方法与
Ignore
属性不会被报告为错误,但它们是完全隐藏来自TRX报告。
我个人的理解如下:
use the [Ignore]
属性(暂时)禁用/跳过该方法:
[TestMethod]
[Ignore] // <== disabled through "Ignore" attribute
public void Test001()
{
//execute some stuff ...
Assert.IsTrue(...);
//execute some stuff ...
Assert.AreEqual(...);
}
do not滥用Inconclusive
为此目的断言:
[TestMethod]
public void Test002()
{
Assert.Inconclusive(); // <== misuse of "Inconclusive" to skip this test
//execute some stuff ...
}
反而,Inconclusive
应该使用有条件的:仅当我们无法判断要测试的组件是否按预期工作时。
例如,如果external我们依赖的资源在测试执行时不可用:
[TestMethod]
public void Test003()
{
//check if the server is running,
//otherwise can can't test our local client component!
if (!WebServiceAvailable())
{
Assert.Inconclusive(); // <== skip remaining code because the resource is not available
}
//execute some stuff ...
Assert.AreEqual(...);
//execute some stuff ...
Assert.AreEqual(...);
}
_ _
结论:
禁用/跳过测试的逻辑方法是使用[Ignore]
属性。
我清楚地看到当前的行为mstest.exe
不报告任何被忽略的测试bug这应该得到解决。
请随意对以下错误报告进行投票:
-
https://connect.microsoft.com/VisualStudio/feedback/details/779743/ https://connect.microsoft.com/VisualStudio/feedback/details/779743/
-
http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2088845 http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2088845
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)