返回提交历史
Modified
README.md
+29
-21
Added
README.zh-CN.md
+173
-0
XFEstudio/XFEExtension.NetCore.XUnit
docs: add English README as primary, rename Chinese README to README.zh-CN.md, add badges to both
Agent-Logs-Url: https://github.com/XFEstudio/XFEExtension.NetCore.XUnit/sessions/1e59d50b-7b6d-4913-9202-3be31ef11249 Co-authored-by: XFEstudio <132526994+XFEstudio@users.noreply.github.com>
8de4c99
代码差异
2 个文件
+202
-21
@@ -1,23 +1,30 @@
1
1
# XFEExtension.NetCore.XUnit
2
2
3
## 描述
3
[](https://www.nuget.org/packages/XFEExtension.NetCore.XUnit)
4
[](https://www.nuget.org/packages/XFEExtension.NetCore.XUnit)
5
[](https://opensource.org/licenses/MIT)
6
[](https://dotnet.microsoft.com/download/dotnet/8.0)
4
7
5
XUnit测试框架,使得用户不需要编写Main函数,只需要在需要测试的类或者方法上面加上相对于的特性即可。
8
English | [中文](./README.zh-CN.md)
6
9
7
## 示例
10
## Description
8
11
9
### 快速编写无参测试用例(CTest和MTest)
12
XFEExtension.NetCore.XUnit is an XUnit-based testing framework that lets you run tests without writing a `Main` method. Simply annotate the classes or methods you want to test with the provided attributes.
13
14
## Examples
15
16
### Quick parameterless test cases (CTest & MTest)
10
17
11
18
```csharp
12
19
[CTest]
13
20
//[CTest]
14
//可添加多个测试用例
21
// Multiple test cases can be added
15
22
public class TestClass
16
23
{
17
24
[MTest]
18
25
//[MTest]
19
26
//[MTest]
20
//可添加多个测试用例
27
// Multiple test cases can be added
21
28
public void TestMethod()
22
29
{
23
30
Console.WriteLine("Hello World!");
@@ -27,7 +34,7 @@ public class TestClass
27
34
28
35
---
29
36
30
### 带参数的测试用例
37
### Test cases with parameters
31
38
32
39
```csharp
33
40
[CTest]
@@ -45,7 +52,7 @@ public class TestClass
45
52
46
53
---
47
54
48
### 使用断言(通过继承类)
55
### Assertions (via inheritance)
49
56
50
57
```csharp
51
58
[CTest]
@@ -55,14 +62,14 @@ public class TestClass : XFECode
55
62
[MTest(2, 3)]
56
63
public void TestMethod(int a, int b)
57
64
{
58
Assert(a + b == 3, "不等于3");
65
Assert(a + b == 3, "Not equal to 3");
59
66
}
60
67
}
61
68
```
62
69
63
70
---
64
71
65
### 使用断言(不继承)
72
### Assertions (without inheritance)
66
73
67
74
```csharp
68
75
[CTest]
@@ -72,14 +79,14 @@ public class TestClass
72
79
[MTest(2, 3)]
73
80
public void TestMethod(int a, int b)
74
81
{
75
XFECode.Assert(a + b == 3, "不等于3");
82
XFECode.Assert(a + b == 3, "Not equal to 3");
76
83
}
77
84
}
78
85
```
79
86
80
87
---
81
88
82
### 判断返回值是否相等(MRTest)
89
### Verify return value equality (MRTest)
83
90
84
91
```csharp
85
92
[CTest]
@@ -97,13 +104,13 @@ public class TestClass
97
104
98
105
---
99
106
100
### 为测试用例添加描述(CNTest和MNTest)
107
### Add descriptions to test cases (CNTest & MNTest)
101
108
102
109
```csharp
103
[CTest("这是一个测试类")]
110
[CTest("This is a test class")]
104
111
public class TestClass
105
112
{
106
[MNTest("这是一个测试方法")]
113
[MNTest("This is a test method")]
107
114
public void TestMethod()
108
115
{
109
116
Console.WriteLine("Hello World!");
@@ -113,13 +120,13 @@ public class TestClass
113
120
114
121
---
115
122
116
### 同时添加描述和结果对比(MNRTest)
123
### Add description and return-value comparison together (MNRTest)
117
124
118
125
```csharp
119
[CTest("这是一个测试类")]
126
[CTest("This is a test class")]
120
127
public class TestClass
121
128
{
122
[MNRTest("这是一个测试方法", 1, 2, 3)]
129
[MNRTest("This is a test method", 1, 2, 3)]
123
130
public int TestMethod(int a, int b)
124
131
{
125
132
return a + b;
@@ -129,13 +136,14 @@ public class TestClass
129
136
130
137
---
131
138
132
### 设置测试类的初始化方法(SetUp)
139
### Set an initialization method for the test class (SetUp)
133
140
134
141
```csharp
135
142
[CTest]
136
143
public class TestClass
137
144
{
138
145
string initWord;
146
139
147
[SetUp]
140
148
public void SetUp()
141
149
{
@@ -152,7 +160,7 @@ public class TestClass
152
160
153
161
---
154
162
155
### 直接测试静态方法(SMTest)
163
### Test static methods directly (SMTest)
156
164
157
165
```csharp
158
166
public class TestClass
@@ -163,4 +171,4 @@ public class TestClass
163
171
Console.WriteLine("Hello World!");
164
172
}
165
173
}
166
```
174
```
@@ -0,0 +1,173 @@
1
# XFEExtension.NetCore.XUnit
2
3
[](https://www.nuget.org/packages/XFEExtension.NetCore.XUnit)
4
[](https://www.nuget.org/packages/XFEExtension.NetCore.XUnit)
5
[](https://opensource.org/licenses/MIT)
6
[](https://dotnet.microsoft.com/download/dotnet/8.0)
7
8
[English](./README.md) | 中文
9
10
## 描述
11
12
XUnit测试框架,使得用户不需要编写Main函数,只需要在需要测试的类或者方法上面加上相对于的特性即可。
13
14
## 示例
15
16
### 快速编写无参测试用例(CTest和MTest)
17
18
```csharp
19
[CTest]
20
//[CTest]
21
//可添加多个测试用例
22
public class TestClass
23
{
24
[MTest]
25
//[MTest]
26
//[MTest]
27
//可添加多个测试用例
28
public void TestMethod()
29
{
30
Console.WriteLine("Hello World!");
31
}
32
}
33
```
34
35
---
36
37
### 带参数的测试用例
38
39
```csharp
40
[CTest]
41
public class TestClass
42
{
43
[MTest(1, 2)]
44
[MTest(2, 3)]
45
[MTest(3, 4)]
46
public void TestMethod(int a, int b)
47
{
48
Console.WriteLine(a + b);
49
}
50
}
51
```
52
53
---
54
55
### 使用断言(通过继承类)
56
57
```csharp
58
[CTest]
59
public class TestClass : XFECode
60
{
61
[MTest(1, 2)]
62
[MTest(2, 3)]
63
public void TestMethod(int a, int b)
64
{
65
Assert(a + b == 3, "不等于3");
66
}
67
}
68
```
69
70
---
71
72
### 使用断言(不继承)
73
74
```csharp
75
[CTest]
76
public class TestClass
77
{
78
[MTest(1, 2)]
79
[MTest(2, 3)]
80
public void TestMethod(int a, int b)
81
{
82
XFECode.Assert(a + b == 3, "不等于3");
83
}
84
}
85
```
86
87
---
88
89
### 判断返回值是否相等(MRTest)
90
91
```csharp
92
[CTest]
93
public class TestClass
94
{
95
[MRTest(1, 2, 3)]
96
[MRTest(2, 3, 5)]
97
[MRTest(3, 4, 7)]
98
public int TestMethod(int a, int b)
99
{
100
return a + b;
101
}
102
}
103
```
104
105
---
106
107
### 为测试用例添加描述(CNTest和MNTest)
108
109
```csharp
110
[CTest("这是一个测试类")]
111
public class TestClass
112
{
113
[MNTest("这是一个测试方法")]
114
public void TestMethod()
115
{
116
Console.WriteLine("Hello World!");
117
}
118
}
119
```
120
121
---
122
123
### 同时添加描述和结果对比(MNRTest)
124
125
```csharp
126
[CTest("这是一个测试类")]
127
public class TestClass
128
{
129
[MNRTest("这是一个测试方法", 1, 2, 3)]
130
public int TestMethod(int a, int b)
131
{
132
return a + b;
133
}
134
}
135
```
136
137
---
138
139
### 设置测试类的初始化方法(SetUp)
140
141
```csharp
142
[CTest]
143
public class TestClass
144
{
145
string initWord;
146
[SetUp]
147
public void SetUp()
148
{
149
initWord = "Hello World!";
150
}
151
152
[MTest]
153
public void TestMethod()
154
{
155
Console.WriteLine(initWord);
156
}
157
}
158
```
159
160
---
161
162
### 直接测试静态方法(SMTest)
163
164
```csharp
165
public class TestClass
166
{
167
[SMTest]
168
public static void TestMethod()
169
{
170
Console.WriteLine("Hello World!");
171
}
172
}
173
```