C# 如何在[Setup]或[OneTimeSetup]中传递参数,以便在测试类中不调用该方法?

C# 如何在[Setup]或[OneTimeSetup]中传递参数,以便在测试类中不调用该方法?,c#,nunit,extentreports,C#,Nunit,Extentreports,在TestNg中,我们有@BeforeMethod,可以在其中传递参数。 但是在Nunit中,我得到了一个异常“OneTimeSetUp:SetUp和TearDown方法不能有参数:TestInitialize”,我试图为类中的每个测试创建扩展报告,而不在每个[test]方法中调用.CreateTest方法 [SetUp] public void TestInitialize(MethodInfo method) { StartReport(TestContext.CurrentCo

在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);

  }




如果您只需要
设置中当前测试的名称
,请使用
TestContext.CurrentContext.test.name
。还有其他属性,如
FullName
MethodName
,这取决于您希望在报表中看到的内容


也就是说,即使使用
设置
,这也是一种非常“繁忙”的报告方式。NUnit还支持引擎扩展,它允许您在测试程序集本身之外创建报告。此外,还可以简单地编写一个程序,从测试运行中读取XML结果文件并创建一个报告。

它说,不能在[Setup]中使用param。你想做什么?@Alex TinLe我正在尝试创建测试报告,但没有提及。在每个方法中创建测试。我只想提一次,因此它适用于每一种[测试]方法,也适用于任何关于此的文档。这类似于TestNG.xml文件。我所需要的是一些输出,如总通过、失败、跳过报告是。它在NUnit文档中。。。