如何使测试方法在Visual Studio单元测试中不可运行

8 c# testing unit-testing visual-studio-2010

如何使测试方法在Visual Studio单元测试中不可运行?使用Visual Studio 2010和.NET 4.0.

假设我有10种测试方法,其中1种测试方法由于外部依赖性而无法工作.如果我想要全部运行10,那么我将在一次测试中得到错误.

一种解决方案是:不要运行测试.但我需要知道,是否有任何属性或类似的东西,它只是绕过测试而不会运行.

我尝试使用[WorkItem(1234)]Attribute,但测试仍在运行.

任何帮助是极大的赞赏.

Bel*_*gix 27

是的,您可以将Ignore属性添加到要跳过的测试:

[TestMethod, Ignore]
public void ThisTestWontRun()
{
    // Test code here
}
Run Code Online (Sandbox Code Playgroud)