Boris
Boris

Reputation: 8941

How add outputs to the NUnit HTML report

I'm using NUnit3 via the console runner. In my test cases I write some outputs like this:

  TestContext.Out.WriteLine($"Tested product: {productName}");
  TestContext.Out.WriteLine($"Backend: {backend}");
  TestContext.Out.WriteLine($"Tester Version: {testerVersion}");

These appear in the .xml report just fine:

<output><![CDATA[XLA Standard Version: 2.2.0
Backend: TCP
Tester Version: 2.0.0.0
Local RTC version: 2.0.0.0
]]></output>

But since the .xml results are barely human readable, I use a HTML transformation by adding the following parameter to the console runner:

--result=TestResult.html;transform=html-report-bootstrap.xslt

This then turns the .xml report into a nice .html report. But sadly all the outputs are missing in the report. I tried different .xslt files from the NUnit repository, but none seems to keep the outputs.

What is the correct way to create outputs in test cases that will appear in HTML reports?

Upvotes: 0

Views: 747

Answers (2)

ra_tester
ra_tester

Reputation: 252

I worked on generating Allure reports for tests in C# recently and I can share what I discovered.

There are many NUnit test report adapter to use, but I managed to setup and use with success Nure and Allure (this is very popular actually, maintained and has many features)

PS: if you need additional detailed steps for install and usage you can check my notes:

Upvotes: 0

Shah
Shah

Reputation: 1399

You might have found the solution by now but I came across the same problem and posting my solution hoping it might help someone else.

Output statements are correctly included into html file when its get transformed and its shown when clicked on Test Name. But the real problem is when we click on Test Name, nothing happens. Click event is not working because script tags for bootstrap js file is not correctly transformed when converted to html.

So open html-report-bootstrap.xslt in any editor and you will find the 3 .js files added as below at end:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-q2kxQ16AaE6UbzuKqyBE9/u/KzioAlnx2maXQHiDX9d4/zp8Ok3f+M7DPm+Ib6IU" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-pQQkAEnwaBkjpqZ8RU1fF1AKtTcHJwFl3pblpTlHXybJjHpMYo79HY3hIi4NKxyj" crossorigin="anonymous"></script>

But when it gets transformed to html file, all 3 js files are added as below with self-closing script tag and it doesn't work in Chrome / Firefox browsers. So click event on Test name doesn't work. Check this question here for more info.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js" />
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-q2kxQ16AaE6UbzuKqyBE9/u/KzioAlnx2maXQHiDX9d4/zp8Ok3f+M7DPm+Ib6IU" crossorigin="anonymous" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-pQQkAEnwaBkjpqZ8RU1fF1AKtTcHJwFl3pblpTlHXybJjHpMYo79HY3hIi4NKxyj" crossorigin="anonymous" />

So as a temp solution for now, I modified the html-report-bootstrap.xslt file and added some JS in between tags as below:

//include the full path
<script src="jquery.js">let x;</script>
<script src="popper.min.js">let y;</script>
<script src="bootstrap.min.js">let z;</script>

So now when it gets transformed to html there is no more self-closing script tag and you can see your output statements when clicked on Test Name as below:

report image

Upvotes: 0

Related Questions