0

Current: We have Hybrid test framework using C# and Nunit. At end of all test execution, it creates TestResult.xml

Planning to implement: which later to be pushed in Jira-Xray via API through c# code.

Challenging part: but the challenge is if I am waiting for whether TestResult.xml file is created or not , it always sends me false. TestResult.xml only gets creates when 100% of codes are executed. including [TearDown] attribute. Even if I use wait, Thread, Task to check whether TestResult.xml file is created or not the Nunit thinks, still some code is getting executed, so it won't create TestResult.xml unless all codes are executed.

I want to send TestResult.xml to Jira-XRAY and from the response get all the test case ID and send mail with the list.

Note: The test frame work has configure setting testResult.runsettings.

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
  <NUnit>
    <TestOutputXml>C:\ProgramData</TestOutputXml>
  </NUnit>
</RunSettings>

Somebody please help me to fix this.

  1. Is it possible to have the TestResult.xml create just after the test is exusted and keep updating with the ongoing test result.
  2. Is it possible to create the TestResult.xml before TearDown in Nunit. OR Any other suggestion

Note: I am able to push TestResult.xml via Postman to Jira-Xray API and works fine, but same thing I wanna use it via code and that can only be achived if TestResult.xml gets create before Nunit reaches to TearDown attribute.

Vivek Sharma
  • 29
  • 2
  • 12
  • Which version of NUnit are you using? – Sérgio Feb 09 '23 at 10:14
  • 2. how are you exactly running the tests ? Programmaticaly using ITestEngine API? https://docs.nunit.org/articles/nunit-engine/Test-Engine-API.html 3. have you tried using the [OneTimeTearDown] approach? https://docs.nunit.org/articles/nunit/writing-tests/attributes/setupfixture.html#example – Sérgio Feb 09 '23 at 10:24
  • @Sérgio I am using Nunit 3.13.3 and On local machine, I am running manually, like select test case ,mouse right click and run `[OneTimeTearDown] public void ExtentClose() { extent.Flush(); ImportResult_JiraXray.uploadXMLtoJiraXray("TestResultXML file"); LaunchBrowser.LaunchBrowser.launchChromebrowser(); Mailkitsender.mail(mailer.mailFrom, mailer.mailTo, mailer.mailSubject, Constants.APIexecutedcuurentCount, Constants.passCase, Constants.failCase); }` – Vivek Sharma Feb 09 '23 at 13:13

2 Answers2

0

TestResult.xml is created by the runner after all tests are run. Since you are using a .runsettings file, I assume your runner is the NUnit Visual Studio test adapter.

The file is created only at the end of the run because it needs to be a complete, valid XML file. Runners receive events as each test is run and so it's possible to send each result somewhere but for that you would have to create your own runner.

However, I think this is something of an xy problem: you are focused on using a file, which is not yet available when you want it. If you explain more exactly what you want to accomplish using the information in that file, we can probably offer alternatives.

Charlie
  • 12,928
  • 1
  • 27
  • 31
  • Its exactly what you had described here, My requirement is get the TestResultXML , push it to Jira-Xray get all the newly created test plan ID , test case ID and then mail the information. Currently I am unable to push XML because its not getting generate unless my TearDown is completed – Vivek Sharma Feb 09 '23 at 13:41
  • 1
    In that case, the answer stands. You clearly can't send it until after the runner creates it. :-) That can't happen until after all the code in your test assembly has run to completion. Because the _runner_ creates the file, an alternative way to automate this can't be given without knowing which of many possible runners you are using. That's equally important to know as the version of NUnit. – Charlie Feb 10 '23 at 15:59
0

For those who might experience the same as I have posted above, here is the solution. If you are working with C# Nuint and then want to push the Nunit generated.XML to Jira-Xray , here is the workaround.

Problem: Unless Nunit test case won't end, it won't generate XML file, and with the same solution you won't be able to push the XML to Jira xray API

Solution: If you are capturing No. of test case Pass, failed, Skipped or any other status. Store those result in light db (SQLite db) When your Nunit test case ends, it is expected the DB will have all the required information and Testresult xml will also get generated.

Now, write down different solutions which read the database value and push the XML to Jira API And then you can send the report and share the TestPlan ID which you will be receiving when you push the XML to Jira-Xray via SMTP or any communication source.

Note: If you try any lengthy process in TearDown or end of Nunit solution it won't help you because Nunit still thinks something is still in process so it will hold the XML creation, even if you wait for 1 eternity, whether the XML has been generated or not in the same solution, so it is advised to have a different solution.

Once you are done with your solution then you can add in Jenkins under post build script.

Vivek Sharma
  • 29
  • 2
  • 12