Skip to content

Commit

Permalink
include xunit
Browse files Browse the repository at this point in the history
  • Loading branch information
fangdatto committed Jun 10, 2024
1 parent 82839f6 commit 29111bc
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
82 changes: 82 additions & 0 deletions Solution1/UnitTestProject/TestsCalculatorX.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using Xunit;
using System;
using TestLibrary;
namespace UnitTestProject
{
public class CalculatorTests
{
private readonly MyCalculator _calculator;

public CalculatorTests()
{
_calculator = new MyCalculator();
}

[Fact]
public void Add_SimpleValues_ShouldReturnCorrectSum()
{
// Arrange
int a = 5;
int b = 3;

// Act
int result = _calculator.Add(a, b);

// Assert
Assert.Equal(8, result);
}

[Fact]
public void Subtract_SimpleValues_ShouldReturnCorrectDifference()
{
// Arrange
int a = 5;
int b = 3;

// Act
int result = _calculator.Subtract(a, b);

// Assert
Assert.Equal(2, result);
}

[Fact]
public void Multiply_SimpleValues_ShouldReturnCorrectProduct()
{
// Arrange
int a = 5;
int b = 3;

// Act
int result = _calculator.Multiply(a, b);

// Assert
Assert.Equal(15, result);
}

[Fact]
public void Divide_SimpleValues_ShouldReturnCorrectQuotient()
{
// Arrange
int a = 6;
int b = 3;

// Act
double result = _calculator.Divide(a, b);

// Assert
Assert.Equal(2.0, result, 1);
}

[Fact]
public void Divide_ByZero_ShouldThrowDivideByZeroException()
{
// Arrange
int a = 6;
int b = 0;

// Act & Assert
Assert.Throws<DivideByZeroException>(() => _calculator.Divide(a, b));
}
}
}
9 changes: 9 additions & 0 deletions Solution1/UnitTestProject/UnitTestProject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="125.0.6422.14100" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TestLibrary\TestLibrary.csproj" />
Expand Down

0 comments on commit 29111bc

Please sign in to comment.