Skip to content

Instantly share code, notes, and snippets.

@digicjm
Last active February 6, 2025 23:34
Show Gist options
  • Save digicjm/8d0b79f22b3c4ad46cf50e7321947a74 to your computer and use it in GitHub Desktop.
Save digicjm/8d0b79f22b3c4ad46cf50e7321947a74 to your computer and use it in GitHub Desktop.
using Xunit;
public class CalculatorTests
{
private readonly Calculator _calculator;
// Constructor-based setup (no [TestInitialize])
public CalculatorTests()
{
_calculator = new Calculator();
}
[Fact] // Equivalent to [TestMethod] in MSTest
public void Add_ShouldReturnCorrectSum_WhenNumbersAreIntegers()
{
var result = _calculator.Add(2, 3);
Assert.Equal(5, result); // xUnit assertion
}
[Theory] // Supports data-driven tests
[InlineData(2, 3, 5)]
[InlineData(-1, -1, -2)]
public void Add_ShouldReturnExpectedResults_WhenNumbersAreIntegers(int a, int b, int expected)
{
var result = _calculator.Add(a, b);
Assert.Equal(expected, result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment