简体   繁体   English

如何使用Nunit自定义结果编写器

[英]How to use Nunit custom result writer

https://github.com/nunit/docs/wiki/Result-Writers https://github.com/nunit/docs/wiki/Result-Writers

I'm trying to write customresults for my application using Nunit. 我正在尝试使用Nunit为我的应用程序编写customresults。 But I'm not getting anywhere as I am not able to find any sample on how to implement. 但是我找不到任何方法,因为我找不到任何有关如何实现的示例。 Any idea? 任何想法?

[Extension]
[ExtensionProperty("Format", "custom")]
public class CustomResultWriterFactory : IResultWriter
{
    ...
}

It seems that your question is not really about how to implement a writer (since you have already done that) but how to install it so that NUnit will use it. 似乎您的问题不是真正的关于如何实现writer的问题(因为您已经完成了),而是如何安装它以便NUnit使用它。 Is that correct? 那是对的吗? In any case, that's what I'm answering. 无论如何,这就是我要回答的。 :-) :-)

I could be more specific if I knew how you are using NUnit because (unfortunately) there are some differences in what you have to do. 如果我知道您如何使用NUnit,我可能会更具体,因为(不幸的是)您要做的事情有些差异。 I'll assume you run tests using the NUnit console runner, since that's the only way to use the format option. 我假设您使用NUnit控制台运行程序运行测试,因为这是使用format选项的唯一方法。 Further, I will assume you installed the console using the nuget package. 此外,我假设您使用nuget软件包安装了控制台。 If you did something else, minor adjustments are needed to the steps you should follow. 如果您做了其他事情,则需要对应该执行的步骤进行细微调整。

  1. Look in the directory where the console runner and engine are installed. 在安装控制台运行程序和引擎的目录中查找。 It should be in something like packages\\NUnit.ConsoleRunner.3.8.0\\tools depending on the version you are using. 根据所使用的版本,它应该位于packages\\NUnit.ConsoleRunner.3.8.0\\tools类的文件中。

  2. You should see nunit.engine.dll in that directory as well as a file named nunit.nuget.addins . 您应该在该目录中看到nunit.engine.dll以及名为nunit.nuget.addins的文件。 That .addins file is set up to find any extension packages, which are also installed using nuget. 设置该.addins文件以查找所有扩展包,这些扩展包也使用nuget安装。 If you had a nuget package for your own extension and installed it, NUnit would find it immediately. 如果您有自己扩展的nuget软件包并安装了它,NUnit会立即找到它。 Let's assume you do not, however. 让我们假设您没有。

  3. In the same directory, create a new text file with file type .addins . 在同一目录中,创建一个文件类型为.addins的新文本文件。 You can use any name, so long as it doesn't conflict with any other file in the directory. 您可以使用任何名称,只要它不与目录中的任何其他文件冲突即可。 Edit the file so it contains one line with the absolute or relative path to your extension. 编辑文件,使其包含一行,其中包含扩展名的绝对或相对路径。 For example: 例如:

    ....\\my\\extensions\\CustomReportWriter.dll .... \\ my \\ extensions \\ CustomReportWriter.dll

  4. Run the console runner with the option --list-extensions . 使用--list-extensions选项运行控制台运行--list-extensions You should see your extension listed. 您应该看到扩展名已列出。

  5. Run the console specifying --result:path/to/result/file.result.xml;format=custom . 运行指定--result:path/to/result/file.result.xml;format=custom的控制台。 You should get your custom output. 您应该获得自定义输出。

NOTE: As you see, I made a lot of assumptions, which could be wrong. 注意:如您所见,我做了很多假设,这可能是错误的。 That's because you didn't give us a lot of info in your question and I felt this was friendlier than just saying "Write better questions!" 那是因为您在问题中没有给我们提供很多信息,我觉得这比只说“写出更好的问题!”更友好。 But please learn how to write better questions that give all the information needed to help you. 但是,请学习如何编写更好的问题,以提供帮助您所需的所有信息。 :-) :-)

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

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