1

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

I'm trying to write customresults for my application using Nunit. 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
{
    ...
}
rohit singh
  • 1,239
  • 3
  • 15
  • 26
  • 1
    https://github.com/nunit/nunit-v2-result-writer/blob/master/src/extension/NUnit2XmlResultWriter.cs – stuartd Jun 13 '18 at 09:59
  • Thanks stuart. I have written my custom result writer but how can I replace it with the actual result writer. I can't find a way to link it or where to add it inside code to make the change happen. – rohit singh Jun 13 '18 at 10:47

1 Answers1

1

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. 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. I'll assume you run tests using the NUnit console runner, since that's the only way to use the format option. Further, I will assume you installed the console using the nuget package. 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.

  2. You should see nunit.engine.dll in that directory as well as a file named nunit.nuget.addins. That .addins file is set up to find any extension packages, which are also installed using nuget. If you had a nuget package for your own extension and installed it, NUnit would find it immediately. Let's assume you do not, however.

  3. In the same directory, create a new text file with file type .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

  4. Run the console runner with the option --list-extensions. You should see your extension listed.

  5. Run the console specifying --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. :-)

Charlie
  • 12,928
  • 1
  • 27
  • 31