Skip to main content

Report C# NUnit Test Results to Vansah

Configure the Vansah C# sample binding, report NUnit and Selenium results against readable case and Jira work item keys, and verify the saved Test Runs.

Use the Vansah C# sample binding to report automation results from a .NET test project. This example records a Quick Test result for an existing Test Case linked to a Jira work item.

Before you begin

  • Use a C# test project with compatible NUnit, Selenium, and Newtonsoft.Json dependencies. The published demo targets .NET 6 and NUnit 3; review its older dependencies for compatibility with your environment.

  • Create a Vansah API token and copy your workspace’s API Connect URL. The token account needs Jira space access and permission to execute the cases.

  • Link an existing Test Case, such as DEMO-C46, to a Jira work item, such as DEMO-123.

  • Complete any run properties required by your Jira space. Use values from your own Jira space.

1. Add and configure the binding

Get VansahNode.cs from the sample repository and include it in your test project. Add the dependencies used by the file if your project does not already have them.

VansahNode.cs included in a C# test project

In your copy of VansahNode.cs, replace the existing vansah_Url and vansah_Token declarations with the following configuration fragment. Keep the URL declaration before the endpoint declarations that use it. These environment variables are configuration added to your copy; the original sample contains a fixed host and token placeholder.

private static string vansah_Url =
(Environment.GetEnvironmentVariable("VANSAH_URL")
?? throw new InvalidOperationException("Set VANSAH_URL.")).TrimEnd('/');

private static string vansah_Token =
Environment.GetEnvironmentVariable("VANSAH_TOKEN")
?? throw new InvalidOperationException("Set VANSAH_TOKEN.");

Set VANSAH_URL to your API Connect URL without an endpoint path, and VANSAH_TOKEN through your environment or CI secret store. Supply the token value directly; the binding adds it to the Authorization header. Keep credentials out of committed source.

2. Report a test result

The following complete NUnit test reports passed after a successful assertion and failed when the browser action or assertion throws. It rethrows the original failure so NUnit still marks the test as failed. Set APP_URL to your application and change the expected title to a value your test should verify.

using System;
using NUnit.Framework;
using OpenQA.Selenium.Chrome;
using Vansah;

public class CheckoutTests
{
[Test]
public void HomePageLoads()
{
string appUrl = Environment.GetEnvironmentVariable("APP_URL")
?? throw new InvalidOperationException("Set APP_URL.");
var execute = new VansahNode();
execute.SetJira_Issue_Key("DEMO-123");
execute.SetEnvironment_Name("UAT");

using var driver = new ChromeDriver();
try
{
driver.Navigate().GoToUrl(appUrl);
Assert.That(driver.Title, Does.Contain("Welcome"));
}
catch
{
try
{
execute.AddQuickTestFromJiraIssue("DEMO-C46", "failed");
}
catch (Exception reportingError)
{
TestContext.Error.WriteLine(reportingError.Message);
}
throw;
}

execute.AddQuickTestFromJiraIssue("DEMO-C46", "passed");
}
}

Example value

Replace with

DEMO-123

The Jira work item key linked to the case.

DEMO-C46

The existing readable Test Case key.

UAT

An environment from your Jira space; remove the setter if it is optional and not needed.

APP_URL and Welcome

Your application URL and the expected page title.

The Quick Test call records an execution result. It does not automatically run the case’s manual script or upload Selenium screenshots. Use the binding’s step-log methods when you need step-level evidence.

3. Run only the test you intend to report

Build the project, then run the test from your IDE or use this filtered command:

dotnet test --filter FullyQualifiedName~HomePageLoads

Review the demo before running its full test suite. Some original samples create runs and then call removal methods. Run your own selected test against the intended case and work item.

4. Verify the result in Vansah

Open the Jira work item, find the linked case, and inspect its Test Runs. Confirm the case, result, environment, and execution time match the test you ran.

Reported Test Run result visible in the Jira work item’s Vansah panel

The sample binding prints API error messages but does not consistently turn rejected reporting requests into test failures. A passing NUnit test alone does not prove that Vansah received the result. Review output and the saved run; adapt reporting error handling before relying on it as a CI gate.

Troubleshooting

  • Authentication error: check the API Connect URL and token for the same workspace.

  • Case or work item error: verify both readable keys and their existing link.

  • Required property error: supply the configured environment, release, or sprint through the supported setters.

  • No result appears: confirm the binding’s updateVansah setting is 1 and inspect API output before retrying.

The original webinar shows the sample workflow; use the written configuration and assertion example above for this guide.

Did this answer your question?