Skip to content

Instantly share code, notes, and snippets.

@seesharprun
Created June 3, 2025 23:29
Show Gist options
  • Save seesharprun/3942d08bd35d0c0b76467ed43697181f to your computer and use it in GitHub Desktop.
Save seesharprun/3942d08bd35d0c0b76467ed43697181f to your computer and use it in GitHub Desktop.
<Project>
<PropertyGroup>
<EnableMSTestRunner>true</EnableMSTestRunner>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
</PropertyGroup>
</Project>
#:package MSTest@3.*
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class CalculatorTests
{
[TestMethod]
public void TestAddSum()
{
// Arrange
int a = 5;
int b = 10;
int expected = 15;
// Act
int actual = Calculator.Add(a, b);
// Assert
Assert.AreEqual(expected, actual, "The sum of {0} and {1} should be {2}.", a, b, expected);
}
[TestMethod]
[DataRow(1, 1, 2)]
[DataRow(2, 2, 4)]
[DataRow(3, 3, 6)]
[DataRow(0, 0, 1)] // This will fail as 0 + 0 != 1
public void AddIntegers_FromDataRowTest(int x, int y, int z)
{
// Act
int a = x;
int b = y;
int expected = z;
// Act
int actual = Calculator.Add(a, b);
// Assert
Assert.AreEqual(expected, actual, "The sum of {0} and {1} should be {2}.", a, b, expected);
}
}
class Calculator
{
public static int Add(int a, int b) => a + b;
}
name: Validate
on:
workflow_dispatch:
permissions:
contents: read
jobs:
validate:
name: Run validation script
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.x
- name: Install .NET tools
run: |
dotnet new tool-manifest
dotnet tool install --local DotnetCtrfJsonReporter
- name: Run .NET unit tests
run: |
dotnet run validate.cs --results-directory "tst" --report-trx --report-trx-filename "results.trx" --no-ansi --ignore-exit-code "2"
- name: Generate CTRF test report
run: |
dotnet tool run DotnetCtrfJsonReporter --test-tool "mstest" --trx-path "tst/results.trx" --output-directory "ctrf" --output-filename "report.json"
- name: Publish CTRF test report
uses: ctrf-io/github-test-reporter@v1
with:
report-path: '**/ctrf/report*.json'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment