鼎鼎知识库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2020.11.1单元测试使用xunit.md 651B

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