Skip to main content

NUnit Integration

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

Install

dotnet add package TMS.SDK

Or add to your .csproj:

MyTests.csproj
<ItemGroup>
<PackageReference Include="TMS.SDK" Version="1.0.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 ProvaLab.io 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 ProvaLab.io 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 ProvaLab.io output alongside NUnit's normal output:

ProvaLab.io NUnit Integration
Test Run ID: 857
Project ID: 12

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

ProvaLab.io Test Run Summary
Test Run ID: 857
Total: 3, Passed: 2, Failed: 1, Skipped: 0

View Results in ProvaLab.io

  1. Open ProvaLab.io 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 ProvaLab.io.

Configuration via appsettings.json

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

Disable ProvaLab.io 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 ProvaLab.io
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:
dotnet add package TMS.SDK
  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 ProvaLab.io summary
  3. Open ProvaLab.io 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 ProvaLab.io: Check that [TMSTestCase] attribute is on each test method and [TMSFixture] is on the class
  • Package not found: Verify the ProvaLab.io NuGet feed is configured in your NuGet.config