Kon*_*zik 7 .net unit-testing xunit.net visual-studio test-explorer
假设我有带有如下签名的集成测试:
[Fact]
[Trait("Category", "Integration")]
public async Task FooTest()
Run Code Online (Sandbox Code Playgroud)
如果我只想运行单元测试,在 dotnet core 中我可以有选择地运行测试:
[Fact]
[Trait("Category", "Integration")]
public async Task FooTest()
Run Code Online (Sandbox Code Playgroud)
如何使用 Visual Studio 测试资源管理器实现相同的目标?
我考虑过使用.runsettings 文件,但它似乎不支持向其传递过滤器参数。
我不想使用播放列表文件,因为我必须手动使其与单元或集成测试的任何更改保持同步。
小智 1
我知道您说过您不想使用播放列表,但我认为这可能是最好的答案。
使用Not匹配关键字将排除您的过滤器,因此以下播放列表将包括解决方案中但不属于“集成”类别的任何 xUnit 测试。
<Playlist Version="2.0">
<Rule Match="Not" >
<Property Name="Trait" Value="Category [Integration]" />
</Rule>
</Playlist>
Run Code Online (Sandbox Code Playgroud)
这种方法还意味着您在添加更多测试时不需要更新播放列表。它们会被自动拾取。
MSTest 的格式略有不同。
<Playlist Version="2.0">
<Rule Match="Not">
<Property Name="Trait" Value="Integration" />
</Rule>
</Playlist>
Run Code Online (Sandbox Code Playgroud)
您可以通过使用多个Rule元素和All关键字来排除多个特征。
<Playlist Version="2.0">
<Rule Match="All">
<Rule Match="Not" >
<Property Name="Trait" Value="Category [Integration]" />
</Rule>
<Rule Match="Not" >
<Property Name="Trait" Value="Category [foo]" />
</Rule>
<Rule Match="Not" >
<Property Name="Trait" Value="Category [bar]" />
</Rule>
</Rule>
</Playlist>
Run Code Online (Sandbox Code Playgroud)
我从Test Explorer 学习页面上提供的示例开始,并根据 Microsoft 的其他类似 XML 模式进行推断,发现了这一点。我无法在线找到此功能的文档。
| 归档时间: |
|
| 查看次数: |
1622 次 |
| 最近记录: |