Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

c# - NUnit: Accessing the Failure Message in TearDown()

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.

I am looking to do this within TearDown().

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

Ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...