gpt4 book ai didi

xunit - 如何根据测试类中的某些 bool 条件跳过 xUnit.net 测试?

转载 作者:行者123 更新时间:2023-12-05 08:06:44 27 4
gpt4 key购买 nike

我需要跳过基于类中某些 bool 条件的测试方法。是否可以?如何实现?我试过扩展 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()
{

}

}
}

最佳答案

你可以这样做:


public class MyTestClass
{
private const string SomeCondition = "false"

[Fact(Skip=SomeCondition)]
void MyTestMethod()
{

}
}

关于xunit - 如何根据测试类中的某些 bool 条件跳过 xUnit.net 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59163946/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com