处理中NUnit的任何错误 [英] Handle any error in NUnit
问题描述
我有一个标准的NUnit的单元测试。
I have got a standard NUnit unit test.
[TestFixture]
public class MyTest
{
[SetUp]
public virtual void Setup()
{
}
[TearDown]
public void CleanUp()
{
}
[Test]
public void Test01()
{
Assert.AreEqual(10, 10);
}
[Test]
public void Test02()
{
Assert.AreEqual(4, 1);
}
[Test]
public void Test03()
{
Assert.AreEqual(1, 51);
}
//......a huge amount of Tests
[Test]
public void TestN()
{
Assert.AreEqual(1, 1);
}
}
正如你看到的,有大量的测试在这里。我需要做的是处理任何错误在每个测试,并获取有关该错误的的信息,而修改的测试方法的身体。
As you see, there are a lot of tests here. What I need to do is to handle any error in each test and to get the information about the error without modifying the body of a test method.
因此,在的JUnit
有 TestListener
称为一个接口,它允许以处理任何测试错误,看到错误消息,看到测试等的名称。
So in JUnit
there is an interface called TestListener
which allows to handle any test error, see the error message, see the name of the test, etc.
我没有找到 NUnit的
类似的东西。它是否存在?或者是有办法做到这一点?
I didn't find something similar in NUnit
. Does it exist? Or is there is a way to do it?
推荐答案
这听起来像你可能需要的 EventListeners的的:
It sounds like you probably want EventListeners:
EventListeners的是能够响应发生在测试运行的过程中的事件,通常是通过记录某种信息。需要注意的是EventListeners的异步调用相对于测试的执行和不能够影响测试的实际执行。
EventListeners are able to respond to events that occur in the course of a test run, usually by recording information of some kind. Note that EventListeners called asynchronously with respect to test execution and are not able to affect the actual execution of the test.
这听起来像你感兴趣的这个方法:
It sounds like you'll be interested in this method:
void TestFinished(TestResult result);
(顺便说一句,这似乎有些奇怪,我认为这不正常使用.NET事件的或的提供一个抽象类,无操作界面的实现,但我们去... )
(As an aside, it seems odd to me that this doesn't use normal .NET events or provide a no-op interface implementation in an abstract class, but there we go...)
这篇关于处理中NUnit的任何错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!