我如何在[Setup]或[OneTimeSetup]中传递参数,所以我没有在测试类中调用该方法?

问题描述 投票:0回答:1

在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”我正在尝试...

c# nunit extentreports
1个回答
0
投票

如果您想要的只是SetUp中当前测试的名称,请使用TestContext.CurrentContext.Test.Name。还有其他属性,例如FullNameMethodName,这取决于您希望在报告中看到的内容。

© www.soinside.com 2019 - 2024. All rights reserved.