Skip to content

Commit 63d7679

Browse files
committed
XUnit Setup Project docs added
1 parent 313a9fe commit 63d7679

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

docs/UnitTest/1 Basics.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# XUnit Basics
2+
3+
## Overview
4+
- XUnit is a popular open-source unit testing framework for .NET applications.
5+
- Good support for modern .NET features and is widely adopted in the .NET community.
6+
- [XUnit](https://xunit.net/)
7+
8+
## Setting up XUnit in your project
9+
- Create .Net 8 Class Library project with `MathUtil` class.
10+
- XUnit test project from Visual Studio template.
11+
- Remove Old XUnit package
12+
- Add ` xunit.v3` Nuget package to test project.
13+
- Update `xunit.runner.visualstudio` to latest version.
14+
- Update `Microsoft.NET.Test.Sdk` to latest version.
15+
- Add `MathUtilTest` class to test project.
16+
17+
```csharp title="MathUtil Class"
18+
public static class MathUtil
19+
{
20+
public static int Add(int a, int b)
21+
{
22+
return a + b;
23+
}
24+
public static int Subtract(int a, int b)
25+
{
26+
return a - b;
27+
}
28+
public static int Multiply(int a, int b)
29+
{
30+
return a * b;
31+
}
32+
public static double Divide(int a, int b)
33+
{
34+
if (b == 0)
35+
{
36+
throw new DivideByZeroException("Denominator cannot be zero.");
37+
}
38+
return (double)a / b;
39+
}
40+
}
41+
```
42+
43+
```csharp title="MathUtilTests Class"
44+
public class MathUtilTest
45+
{
46+
[Fact]
47+
public void TestAdd()
48+
{
49+
//Arrange
50+
var a = 1;
51+
var b = 2;
52+
53+
//Act
54+
var result = MathUtil.Add(a, b);
55+
56+
//Assert
57+
Assert.Equal(3, result);
58+
}
59+
}
60+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ markdown_extensions:
5555
- name: mermaid
5656
class: mermaid
5757
format: !!python/name:pymdownx.superfences.fence_code_format
58+
- attr_list # for code block titles and other attributes
5859
- pymdownx.arithmatex: # for rendering math equations
5960
generic: true
6061
- def_list # List extensions

0 commit comments

Comments
 (0)