【发布时间】:2017-05-17 16:31:43
【问题描述】:
我正在尝试在使用内部 ITestResult 接口拆除时获取 NUnit 3 中的测试结果。但是,当我将 ITestResult 对象传递给拆解方法时,我得到“OneTimeSetup:SetUp 或 TearDown 方法的无效签名:TestFinished”,其中 TestFinished 被列为我的拆解方法。
如果我没有通过对象,测试工作正常。我试图将我的 [TearDown] 方法移动到包含测试的实际类而不是我的基类,但会导致相同的错误。我想让我的 TestFinish 函数在每个测试完成时运行,这样我就可以根据通过/失败或异常消息中的内容采取相应的行动,而不是使用我现在拥有的操作结构的测试 try/catch。
下面是我的代码结构:
----一个开始和结束测试并创建一个webdriver对象来使用的文件---
[OneTimeSetUp]
public void Setup()
{
//Do some webdriver setup...
}
----用于设置或拆除测试的基本测试类----
[TestFixture]
public class BaseTestClass
{
//Also use the webdriver object created at [OneTimeSetUp]
protected void TestRunner(Action action)
{
//perform the incoming tests.
try
{
action();
}
//if the test errors out, log it to the file.
catch (Exception e)
{
//Do some logging...
}
}
[TearDown]
public void TestFinished(ITestResult i)
{
//Handle the result of a test using ITestResult object
}
}
----使用BaseTestClass的测试文件----
class AccountConfirmation : BaseTestClass
{
[Test]
public void VerifyAccountData() {
TestRunner(() => {
//Do a test...
});
}
}
【问题讨论】:
标签: c# selenium nunit nunit-3.0