简体   繁体   English

如何将nunit结果发送到数据库

[英]how to get nunit results to a database

Hi I am trying to get the nunit results into a database while it is running. 嗨,我正在尝试将nunit结果运行到数据库中。 So what I really need is a way to see if the test has passed or failed on the teardown so that I can write some code to insert values into the database based on if it passes or fails. 所以我真正需要的是一种方法来查看测试是否已经通过或者已经失败,以便我可以编写一些代码,以便根据数据传递或失败将值插入数据库。

So is it possible to get this information in the teardown if the current running test is in a passing or failing state, as well as information such as test name and if it has failed the reason for failure. 因此,如果当前运行的测试处于通过或失败状态,以及诸如测试名称之类的信息以及是否失败的原因,则可以在拆解中获得此信息。

Thanks 谢谢

In NUnit at or post 2.4.4, you can get the TestResult as it happens using EventListeners - you need to write your results to the DB from the TestFinished method. 在2.4.4或之后的NUnit中,您可以使用EventListeners获取TestResult - 您需要从TestFinished方法将结果写入DB。

void TestFinished(TestResult result);

The name of the test will be that of the most recent TestStarted call: 测试的名称将是最近的TestStarted调用的名称:

void TestStarted(TestName testName);

To do this you have to implement an NUnit addin that implements the EventListeners interface. 为此,您必须实现一个实现EventListeners接口的NUnit插件

Do you want to see results as they happen, or at the end? 您希望在结果发生时或结束时看到结果吗? If you just want to see them at the end, you could get NUnit to write them to an XML file: 如果您只想在最后看到它们,可以让NUnit将它们写入XML文件:

nunit-console /xml:console-test.xml nunit.tests.dll

You could then write a program to parse the XML and load it into a database. 然后,您可以编写一个程序来解析XML并将其加载到数据库中。

To see test results as they happen, you could write your own NUnit log plugin. 要在测试结果发生时查看,您可以编写自己的NUnit日志插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM