[Setup]
public void RunBeforeAnyTest()
{
}
[TearDown]
public void RunAfterEveryTest()
{
}
[Test]
public void Test1()
{
}
[TestCase("case1")]
[Testcase("case2")]
public void Test2()
{
}
在上面的示例中,Setup和TearDown在Test1和Test2之前和之后执行。但我希望它在Test2中的个别测试用例之前和之后执行。是否可以使用nunit框架?我怎样才能做到这一点?
答案 0 :(得分:2)
纠正一些拼写错误后:
[TestFixture]
public class Class1
{
[SetUp]
public void RunBeforeAnyTest()
{
Console.WriteLine("RunBeforeAnyTest");
}
[TearDown]
public void RunAfterEveryTest()
{
Console.WriteLine("RunAfterEveryTest");
}
[Test]
public void Test1()
{
Console.WriteLine("Test1()");
}
[TestCase("case1")]
[TestCase("case2")]
public void Test2(string param)
{
Console.WriteLine($"Test2({param})");
}
}
输出结果为:
RunBeforeAnyTest Test1() RunAfterEveryTest RunBeforeAnyTest Test2(case1) RunAfterEveryTest RunBeforeAnyTest Test2(case2) RunAfterEveryTest
不是你想要的吗?