Is it good practice to include the expected result in a test file?

Consider the following test:

    [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);
    }

Is it wrong to use both the year and the expected results in such test scenarios, instead of creating two different tests (for example, one to expect true, one to expect false?)

thanks

+4
source share
1 answer

No, in fact, I think it would be bad practice to do two tests that will test the same condition, but one “expectation of truth” and “expectation of false”, where everyone expects success and the other - failure ..

. , , .

+6

Source: https://habr.com/ru/post/1624190/


All Articles