Код: Выделить всё
[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 Test2() { ... }
}
Код: Выделить всё
[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}");
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... -attribute