Sfoglia il codice sorgente

使用xunit

master
qdjjx 4 anni fa
parent
commit
15503ffc1c

专题/后端/2020.10.29单元测试实例.md → 专题/后端/2020.10.29单元测试Why.md Vedi File

@@ -35,9 +35,3 @@
35 35
 - NUnit
36 36
 - XUnit
37 37
 
38
-> XUnit的基本面
39
-
40
-最简单的就是
41
-```
42
-
43
-```

+ 29
- 0
专题/后端/2020.11.1单元测试使用xunit.md Vedi File

@@ -0,0 +1,29 @@
1
+# 开始XUnit
2
+
3
+最简单的就是
4
+```
5
+public void PlayerService_GetAllPlayers_InvalidLeage()
6
+{
7
+    //Arrange
8
+    var mockLeageRepo = new MockLeagueRepository().MockIsValid(false);
9
+    var playerService = new PlayerService(new MockPlayerRepository().Object, new MockTeamRepository().Object, mockLeagueRepo.Object);
10
+
11
+    //Act
12
+    var allPlayers = playerService.GetForLeague(1);
13
+
14
+    //Assert
15
+    Assert.Empty(allPlayers);
16
+    mockLeagueRepo.VerifyIsValid(Times.Once());
17
+}
18
+```
19
+
20
+测试数据源
21
+```
22
+--InlineData特性
23
+--ClassData特性
24
+--MemberData特性
25
+--来自外部json文件
26
+--来自TheoryData<>泛型
27
+```
28
+
29
+案例源码:F:\demos\UnitTest\ThirdDemo

Loading…
Annulla
Salva