Unit testing 在测试用例中包含预期结果是一个好的实践吗?

Unit testing 在测试用例中包含预期结果是一个好的实践吗?,unit-testing,testing,tdd,nunit,Unit Testing,Testing,Tdd,Nunit,考虑以下测试: [TestCase(2016, true)] [TestCase(2017, false)] [TestCase(2018, false)] [TestCase(2019, false)] [TestCase(2020, true)] public void When_IsLeapYear_ReturnTrueForLeapYear(int year, bool expectedResult) { //Act

考虑以下测试:

    [TestCase(2016, true)]
    [TestCase(2017, false)]
    [TestCase(2018, false)]
    [TestCase(2019, false)]
    [TestCase(2020, true)]
    public void When_IsLeapYear_ReturnTrueForLeapYear(int year, bool expectedResult)
    {
        //Act
        var result = _sut.IsLeapYear(year);

        //Assert
        Assert.AreEqual(result, expectedResult);
    }
在这样的测试用例中同时包含年份和预期结果,而不是创建两个不同的测试(例如,一个测试预期为真,一个测试预期为假),这是一种糟糕的做法吗


谢谢

不,事实上,我认为做两个测试完全相同,但一个“预期为真”和一个“预期为假”,其中一个预期成功,另一个预期失败,这是一种不好的做法

您只需要这两个测试中的一个。第二种方法没有增加额外的bug捕获值,只是增加了维护负担