【发布时间】:2022-05-19 10:30:07
【问题描述】:
我需要根据类中的某些布尔条件跳过测试方法。 可能吗?如何实现?我曾尝试扩展 FactAttribute,但无法获取 Test 类的实例。
我的代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using Xunit;
namespace XUnitTestProject1
{
public class MyTestClass
{
bool SomeCondition;
public MyTestClass()
{
SomeCondition = false;
}
[Fact] //I WANT TO SKIP THIS TEST AS SOMECONDITON == FALSE
void MyTestMethod()
{
}
}
}
【问题讨论】:
-
不要让逻辑跳过一个测试,而是创建两个测试,将它们放入不同的特征中。所有测试运行器都支持基于 trait 运行/跳过测试。
-
:) 或者你总是可以在测试中做
if (i_want_to_skip_this_test == true) return;
标签: xunit