在TestNg中,我们有@BeforeMethod,可以在其中传递参数。但是在Nunit中,我遇到了一个异常“ OneTimeSetUp:SetUp和TearDown方法必须没有参数:TestInitialize”我试图为类中的每个测试创建范围报告,而没有在每个[Test]方法中都调用.CreateTest方法。
[SetUp]
public void TestInitialize(MethodInfo method)
{
StartReport(TestContext.CurrentContext.Test.Name);
string testName = method.Name;
test = extent.CreateTest(testName);
}
[Test]
public void GetHealthTest()
{
test.Log(Status.Info, "Before calling GetHealth API");
var health = heartbeat.GetHealth();
test.Log(Status.Info, "After GetHealth API call");
Assert.AreEqual(health.StatusCode, HttpStatusCode.OK);
}
在TestNg中,我们有@BeforeMethod,可以在其中传递参数。但是在Nunit中,我遇到了这样的异常:“ OneTimeSetUp:SetUp和TearDown方法必须没有参数:TestInitialize”我正在尝试...
如果您想要的只是SetUp
中当前测试的名称,请使用TestContext.CurrentContext.Test.Name
。还有其他属性,例如FullName
和MethodName
,这取决于您希望在报告中看到的内容。