鼎鼎知识库
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.

开始XUnit

最简单的就是

public void PlayerService_GetAllPlayers_InvalidLeage()
{
    //Arrange
    var mockLeageRepo = new MockLeagueRepository().MockIsValid(false);
    var playerService = new PlayerService(new MockPlayerRepository().Object, new MockTeamRepository().Object, mockLeagueRepo.Object);

    //Act
    var allPlayers = playerService.GetForLeague(1);

    //Assert
    Assert.Empty(allPlayers);
    mockLeagueRepo.VerifyIsValid(Times.Once());
}

测试数据源

--InlineData特性
--ClassData特性
--MemberData特性
--来自外部json文件
--来自TheoryData<>泛型

案例源码:F:\demos\UnitTest\ThirdDemo