Ale*_*der 5 c# unit-testing visual-studio test-explorer
这可能与问题有关:视觉工作室中单元测试的动态播放列表.
我希望能够拥有一个或多个测试播放列表,而不是没有将每个新测试添加到某个播放列表.
我目前有一个包含所有单元测试的播放列表,但是将来我希望有一个由自动集成测试组成的播放列表,应该在提交到TFS之前运行,但不是每次应用程序构建时都运行.
有没有办法做到这一点?
noz*_*man 10
IM不知道类型的,你可以在TFS使用设置的,因为我不是使用TFS,但我知道这是可能的使用类别在两者的NUnit和MSTest的.
使用NUnit,您可以使用-Attribute标记单个测试甚至整个灯具Category:
namespace NUnit.Tests
{
using System;
using NUnit.Framework;
[TestFixture]
[Category("IntegrationTest")]
public class IntegrationTests
{
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
要么
namespace NUnit.Tests
{
using System;
using NUnit.Framework;
[TestFixture]
public class IntegrationTests
{
[Test]
[Category("IntegrationTest")]
public void AnotherIntegrationTest()
{
// ...
}
}
}
Run Code Online (Sandbox Code Playgroud)
并使用nunit-console.exe运行那些:
nunit-console.exe myTests.dll /include:IntegrationTest
Run Code Online (Sandbox Code Playgroud)
MSTest的解决方案非常相似:
namespace MSTest.Tests
{
[TestClass]
public class IntegrationTests
{
[TestMethod]
[TestCategory("IntegrationTests")
public void AnotherIntegrationTest()
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是在这里你必须用该属性标记所有测试,它不能用于装饰整个类.
然后,与NUnit一样,只在IntegrationTests -category中执行这些测试:
使用VSTest.Console.exe
Vstest.console.exe myTests.dll /TestCaseFilter:TestCategory=IntegrationTests
Run Code Online (Sandbox Code Playgroud)
使用MSTest.exe
mstest /testcontainer:myTests.dll /category:"IntegrationTests"
Run Code Online (Sandbox Code Playgroud)
您还可以使用VS的TestExplorer执行某些测试类别.
如上图所示,您可以在TestExplorer的左上角选择一个类别.选择Trait并仅执行您想要的catgegory.
有关更多信息,请参阅MSDN.
| 归档时间: |
|
| 查看次数: |
3660 次 |
| 最近记录: |