Make MSTest respect [Conditional()] attribute?

你离开我真会死。 提交于 2019-12-01 17:04:17

The ConditionalAttribute does not affect whether or not a method is compiled into an application. It controls whether or not calls to the method are compiled into the application.

There is no call to EnsureVerboseLog in this sample. MSTest just sees a method in the assemlby with the TestMethod attribute and correctly executes it. In order to prevent MSTest from running the method you will need to do one of the following

  1. Not compile it into your application (possible through #if's)
  2. Not annotate it with the TestMethod attribute

So, is there a way to exclude certain tests depending on compilation constant other than #if?

Why ignore the obvious? it's readable, does exactly the wanted work, etc...

[TestMethod]
#if !DEBUG
[Ignore]
#endif
public void AnyTest()
{
    // Will invoke for developer and not in test-server!
}

HTH..

Andrew Dimech

A work around is to set the Priority attribute to -1 to your method. Then run mstest with "minpriority:0" as an argument.

[TestMethod()]
[Priority(-1)]
public void Compute_Foo()
{
    This method will not be executed
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!