Steps for setting up a .NET automation testing project
Let’s go through the typical end-to-end steps for setting up a .NET automation testing project and running it in a CI/CD pipeline, covering unit, API, UI, performance, and reporting.
⚙️ 1️⃣ Setting up the Automation Project (Local Setup)
Step 1: Choose the Test Framework
Common .NET test frameworks:
- xUnit → lightweight, parallel-friendly
- NUnit → classic, popular in enterprise
- MSTest → built-in with Visual Studio
Example (xUnit in .csproj):
<ItemGroup>
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0" />
</ItemGroup>
Step 2: Decide the Type of Automation
| Type | Framework/Library |
|---|---|
| Unit testing | xUnit / NUnit |
| API testing | RestSharp / HttpClient + FluentAssertions |
| UI testing | Selenium / Playwright / Cypress (JS) |
| Performance | JMeter / k6 / NBomber (.NET load testing) |
Step 3: Project Structure Example
AutomationFramework/
┣ src/
┃ ┗ MyApp/
┣ tests/
┃ ┣ UnitTests/
┃ ┣ ApiTests/
┃ ┗ UiTests/
┣ drivers/
┣ reports/
┗ ci/
Step 4: Implement Base Classes & Utilities
Example — Base API Test:
public class BaseApiTest
{
protected RestClient client;
public BaseApiTest()
{
client = new RestClient("https://api.example.com");
}
}
Sample Test:
[Fact]
public async Task GetUsers_ShouldReturn200()
{
var request = new RestRequest("/users", Method.Get);
var response = await client.ExecuteAsync(request);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
Step 5: Add Logging & Reporting
Use:
- Serilog for structured logging
- ExtentReports / Allure / ReportUnit for HTML reports
Example with Serilog:
Log.Logger = new LoggerConfiguration()
.WriteTo.File("logs/test.log", rollingInterval: RollingInterval.Day)
.CreateLogger();
🧪 2️⃣ Local Test Execution
Run from CLI:
dotnet test
or run specific tests:
dotnet test --filter TestCategory=Smoke
You can output results in TRX or JUnit XML for CI systems:
dotnet test --logger:"trx;LogFileName=TestResults.trx"
🚀 3️⃣ CI/CD Integration (Azure DevOps / GitHub Actions / Jenkins)
Step 1: Set Up Build Pipeline
Typical stages:
1️⃣ Checkout code
2️⃣ Restore dependencies (dotnet restore)
3️⃣ Build project (dotnet build)
4️⃣ Run unit/API/UI tests (dotnet test)
5️⃣ Publish test results
6️⃣ Deploy to environment (for post-deploy tests)
Step 2: Example – GitHub Actions
name: .NET Test Automation
on: [push, pull_request]
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Run Tests
run: dotnet test --logger "trx;LogFileName=test_results.trx" --results-directory TestResults
Step 3: Example – Azure DevOps YAML
trigger:
- main
pool:
vmImage: 'windows-latest'
steps:
- task: DotNetCoreCLI@2
inputs:
command: 'restore'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
inputs:
command: 'test'
projects: '**/*Tests.csproj'
arguments: '--logger trx'
🧩 4️⃣ Post-Deployment / Regression Testing
After deployment:
- Use Playwright / Selenium Grid / BrowserStack to test in real browsers.
- Use RestSharp or Postman Collections for regression API tests.
- Use NBomber or k6 for performance load testing.
🔒 5️⃣ Security, Quality & Accessibility Gates
- Run OWASP ZAP / SonarQube in CI for vulnerability scanning and code quality.
- Add Pa11y / axe-core for accessibility checks.
📊 6️⃣ Reporting & Notifications
- Publish HTML or JUnit test results as artifacts.
- Send Slack / Teams / Email notification on build failure.
- Integrate Allure Reports or Extent Reports for dashboards.
✅ Summary Flow
| Stage | Tool | Purpose |
|---|---|---|
| Build | dotnet build | Compile code |
| Unit Tests | xUnit / NUnit | Test logic |
| API Tests | RestSharp / HttpClient | Validate endpoints |
| UI Tests | Selenium / Playwright | Validate user journeys |
| Reports | Allure / Extent / trx | View results |
| CI/CD | GitHub / Azure / Jenkins | Continuous delivery |
| Code Quality | SonarQube | Maintain standards |
Published on: Oct 06, 2025, 11:36 PM