[英]How can I pass parameters in a [Setup] or [OneTimeSetup] so I so not have call the method in my test class?
In TestNg We have @BeforeMethod where we can pass parameters.在 TestNg 中,我们有 @BeforeMethod 可以传递参数。 But in Nunit I get this exception "OneTimeSetUp: SetUp and TearDown methods must not have parameters: TestInitialize" I am trying to Create the extent report for each test in the class with out calling .CreateTest method in every [Test] method
但是在 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);
}
If all you want is the name of the current test in your SetUp
, use TestContext.CurrentContext.Test.Name
.如果您只想要
SetUp
当前测试的名称,请使用TestContext.CurrentContext.Test.Name
。 There are other properties, like FullName
and MethodName
as well, depending on what you prefer to see in your report.还有其他属性,例如
FullName
和MethodName
,取决于您希望在报告中看到的内容。
That said, even with use of SetUp
, this is a very "busy" way to do reporting.也就是说,即使使用
SetUp
,这也是一种非常“繁忙”的报告方式。 NUnit also supports engine extensions, which allow you to create reports outside of the test assembly itself. NUnit 还支持引擎扩展,它允许您在测试程序集本身之外创建报告。 In addition, it's possible to simply write a program that reads the XML result file from a test run and creates a report.
此外,还可以简单地编写一个程序,从测试运行中读取 XML 结果文件并创建报告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.