Skip to main content

NUnit Integration

Run your NUnit tests as usual and have results automatically reported to TMS. The SDK provides attributes and a test listener for seamless .NET integration.

Install​

The packages are served from the ProvaLab NuGet feed, not nuget.org. Add the feed next to your .sln:

NuGet.config
<configuration>
<packageSources>
<add key="provalab" value="https://plugins.provalab.io/nuget/index.json" />
</packageSources>
</configuration>

Then install:

dotnet add package TMS.NUnit --version 2.2.0 --source provalab
# or the base client with no framework adapter:
dotnet add package TMS.SDK --version 1.1.0 --source provalab

Or add to your .csproj:

MyTests.csproj
<ItemGroup>
<PackageReference Include="TMS.NUnit" Version="2.2.0" />
</ItemGroup>

Requirements: .NET 6.0+, NUnit 3.13+

Configure​

1. Set environment variables​

export TMS_API_KEY=your-api-key
export TMS_API_URL=https://tms.yourcompany.com
export TMS_ORGANIZATION_ID=1
export TMS_PROJECT_ID=12

On Windows (PowerShell):

$env:TMS_API_KEY = "your-api-key"
$env:TMS_API_URL = "https://tms.yourcompany.com"
$env:TMS_ORGANIZATION_ID = "1"
$env:TMS_PROJECT_ID = "12"

2. Add the TMS attribute to your tests​

Tests/LoginTests.cs
using NUnit.Framework;
using TMS.SDK;

[TestFixture]
[TMSFixture]
public class LoginTests
{
[Test]
[TMSTestCase("TC-101")]
public void ShouldLoginWithValidCredentials()
{
var result = AuthService.Login("[email protected]", "password123");
Assert.That(result.IsSuccess, Is.True);
}

[Test]
[TMSTestCase("TC-102")]
public void ShouldRejectInvalidPassword()
{
Assert.Throws<AuthException>(() =>
{
AuthService.Login("[email protected]", "wrong-password");
});
}

[Test]
[TMSTestCase("TC-103")]
[Category("smoke")]
public void ShouldHandleExpiredAccount()
{
Assert.Throws<AccountExpiredException>(() =>
{
AuthService.Login("[email protected]", "password123");
});
}
}

3. Register the TMS event listener​

Create an assembly-level setup to register the listener:

Tests/TMSSetup.cs
using NUnit.Framework;
using TMS.SDK;

[SetUpFixture]
public class TMSSetup
{
private TMSTestRunManager _runManager;

[OneTimeSetUp]
public void GlobalSetup()
{
_runManager = new TMSTestRunManager();
_runManager.StartRun("NUnit Regression Tests");
}

[OneTimeTearDown]
public void GlobalTeardown()
{
_runManager.CompleteRun();
}
}

Run​

dotnet test

You'll see TMS output alongside NUnit's normal output:

TMS NUnit Integration
Test Run ID: 857
Project ID: 12

[PASS] LoginTests.ShouldLoginWithValidCredentials (0.12s)
[PASS] LoginTests.ShouldRejectInvalidPassword (0.08s)
[FAIL] LoginTests.ShouldHandleExpiredAccount (0.15s)

TMS Test Run Summary
Test Run ID: 857
Total: 3, Passed: 2, Failed: 1, Skipped: 0

View Results in TMS​

  1. Open TMS and go to your project
  2. Click Test Runs in the sidebar
  3. Find the run named "NUnit Regression Tests"
  4. Click into it to see individual test results with error details and stack traces

Advanced Configuration​

Parameterized tests​

[Test]
[TMSTestCase("TC-201")]
[TestCase("[email protected]", "admin123", true)]
[TestCase("[email protected]", "user123", true)]
[TestCase("[email protected]", "wrong", false)]
public void ShouldHandleLogin(string email, string password, bool expected)
{
var result = AuthService.Login(email, password);
Assert.That(result.IsSuccess, Is.EqualTo(expected));
}

Each test case parameter set is reported as a separate result in TMS.

Configuration via appsettings.json​

appsettings.json
{
"TMS": {
"ApiUrl": "https://tms.yourcompany.com",
"ApiKey": "your-api-key",
"OrganizationId": 1,
"ProjectId": 12,
"Environment": "staging"
}
}

Disable TMS for local development​

export TMS_DISABLED=true
dotnet test

Run specific tests​

dotnet test --filter "FullyQualifiedName~LoginTests"

With Selenium WebDriver​

[Test]
[TMSTestCase("TC-301")]
public void ShouldDisplayDashboard()
{
using var driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://app.yourcompany.com/dashboard");

Assert.That(driver.Title, Does.Contain("Dashboard"));

// On failure, capture screenshot for TMS
if (TestContext.CurrentContext.Result.Outcome != ResultState.Success)
{
var screenshot = ((ITakesScreenshot)driver).GetScreenshot();
var path = Path.Combine(TestContext.CurrentContext.WorkDirectory, "failure.png");
screenshot.SaveAsFile(path);
TMSTestRunManager.Current.AttachArtifact(path);
}
}

Verify It Works​

  1. Install the package (with the ProvaLab feed in NuGet.config, see Install):
dotnet add package TMS.NUnit --version 2.2.0 --source provalab
  1. Set your environment variables
  2. Create a simple test:
Tests/TMSVerifyTest.cs
using NUnit.Framework;
using TMS.SDK;

[TestFixture]
[TMSFixture]
public class TMSVerifyTest
{
[Test]
[TMSTestCase("TC-1")]
public void VerifyTmsIntegration()
{
Assert.That(1 + 1, Is.EqualTo(2));
}
}
  1. Run: dotnet test --filter TMSVerifyTest
  2. Check the console for the TMS summary
  3. Open TMS and confirm the test run appears
Common issues
  • "Not configured" message: Make sure environment variables are set. On Windows, use $env: syntax in PowerShell
  • Tests run but nothing in TMS: Check that [TMSTestCase] attribute is on each test method and [TMSFixture] is on the class
  • Package not found: Verify the TMS NuGet feed is configured in your NuGet.config