Lad*_*nka 22 .net resharper unit-testing mstest team-build
什么是使用正确的方式Assert.Inconclusive
,并IgnoreAttribute
在MS单元测试框架?
我们Assert.Inconclusive
主要用于以下测试:
我们这样做是因为:
我们的问题是Inconclusive
测试在TFS和Resharper中都被标记为错误.如果我们使用,IgnoreAttribute
我们将在Resharper中看到这些测试,但MS Test runner和TFS将完全忽略它们.使用IgnoreAttribute
在TFS和MS测试亚军是同样喜欢评论整个测试是无用的.
Opm*_*met 15
我也看到当前实施中的两难选择.
Inconclusive
断言包含在TRX报告中,但mstest.exe(以及vstest.console.exe)将在执行后返回1
(意味着错误).Ignore
属性的TestMethods 不会被报告为错误,但它们在TRX报告中完全隐藏.我个人的理解如下:
使用该[Ignore]
属性(暂时)禁用/跳过该方法:
[TestMethod]
[Ignore] // <== disabled through "Ignore" attribute
public void Test001()
{
//execute some stuff ...
Assert.IsTrue(...);
//execute some stuff ...
Assert.AreEqual(...);
}
Run Code Online (Sandbox Code Playgroud)
千万不能滥用Inconclusive
为此,断言:
[TestMethod]
public void Test002()
{
Assert.Inconclusive(); // <== misuse of "Inconclusive" to skip this test
//execute some stuff ...
}
Run Code Online (Sandbox Code Playgroud)
相反,Inconclusive
应该有条件地使用:只有当我们无法判断要测试的组件是否按预期工作时.
例如,如果我们依赖的外部资源在测试执行时不可用:
[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(...);
}
Run Code Online (Sandbox Code Playgroud)
_ _
结论:
禁用/跳过测试逻辑方式是使用该[Ignore]
属性.
我清楚地看到当前mstest.exe
没有报告任何被忽略的测试的行为是一个应该修复的错误.
随意向上投票以下错误报告:
我想你是如何描述Inconclusive是正确的用法.
虽然根据我的经验,Inconclusive被视为警告而不是错误.事实上,它们在TRX中与错误分开报告:
<TestRun>
<ResultSummary outcome="Inconclusive">
<Counters total="1"
executed="0" error="0" failed="0"
timeout="0" aborted="0" inconclusive="1"
passedButRunAborted="0" notRunnable="0"
notExecuted="0" disconnected="0"
warning="0" passed="0" completed="0"
inProgress="0" pending="0" />
Run Code Online (Sandbox Code Playgroud)
我通常从我的msbuild脚本中的<Exec>任务运行mstest可执行文件,然后查看TRX内部以确定它是否应该使构建失败.
归档时间: |
|
查看次数: |
8500 次 |
最近记录: |