本文介绍了NUnit:在 TearDown() 中访问失败消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将在 NUnit 中运行的自动化测试的结果记录在一个小型数据库中,以便出于各种原因轻松访问和更安全地记录数据.(大约有 550 个自动化测试,运行它们可能需要几天时间)

I'm trying to log the results of automated tests run in NUnit in a small database so that data is easily accessible and more securely logged for various reasons. (There's about ~550 automated tests and running them all can take days)

我已经可以访问测试的结束状态(通过/失败/错误/取消/跳过等),但我想记录额外的详细信息.

I already have access to the ending status of the test (Passed/Failed/Error/Cancelled/Skipped etc..) but I'd like to log the extra detail.

我希望在 TearDown() 中执行此操作.

I am looking to do this within TearDown().

这是我能找到的最接近的东西,但没有给我答案:https://groups.google.com/forum/?fromgroups=#!msg/nunit-discuss/lXxwECvpqFc/IbKOfQlbJe8J

This is the closest thing I could find, but did not provide me with an answer:https://groups.google.com/forum/?fromgroups=#!msg/nunit-discuss/lXxwECvpqFc/IbKOfQlbJe8J

想法?

推荐答案

相信通过NUnit EventListeners.我自己没有使用过这些,但我已将它们添加为书签,以执行与您想要完成的任务类似的操作.

I believe you'll be able to get the information you need with NUnit EventListeners. I haven't used these myself, but I've had them bookmarked to do something similar to what you're trying to accomplish.

这是您要使用的界面.希望您的 TearDown 方法会在 TestFinished 之前被调用,但我无法验证这一点.

Here's the interface you'd be working with. Hopefully your TearDown method would be called just before TestFinished, but I can't verify this.

public interface EventListener
{
    void RunStarted(string name, int testCount );
    void RunFinished(TestResult result);
    void RunFinished(Exception exception);
    void TestStarted(TestName testName);
    void TestFinished(TestResult result);
    void SuiteStarted(TestName testName);
    void SuiteFinished(TestResult result);
    void UnhandledException(Exception exception);
    void TestOutput(TestOutput testOutput);
}

这篇关于NUnit:在 TearDown() 中访问失败消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 23:40