I have a test class with TestFixtureSource with two values: "Unit" and "Integration". These values are values of mode. Based on this mode the class sets dependencies up as mocks or real implementations. Some class tests are actual for both modes, while others are actual only for one of them. I am trying to find how to skip or ignore some tests depending on the mode value. So, I want to do something like the following
[TestFixtureSource(nameof(UnitOrIntegration))]
class Tests(string Mode)
{
[SetUp]
void Setup()
{
if (Mode == "Unit") { ... }
if (Mode == "Integration") { ... }
}
[Test] //actual for both modes
void Test1() { ... }
[Test][WhenModeIs("Unit")]
void Test2() { ... }
[Test][WhenModeIs("Integration")]
void Test3() { ... }
}
I found something that looks like can help
[AttributeUsage(
AttributeTargets.Method,
AllowMultiple = false,
Inherited = false)]
public class WhenModeIsAttribute(string Mode)
: NUnitAttribute, IApplyToTest
{
public void ApplyToTest(Test test)
{
if (/* I need check mode here */)
{
test.RunState = RunState.Ignored;
test.Properties.Set(
PropertyNames.SkipReason,
$"It is not actual for {Mode}");
}
}
}
But I can't find a way to access the mode value. How to do that?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745672289a4639477.html
评论列表(0条)