How to compare Lists in Unit Testing

后端 未结 7 1568
闹比i
闹比i 2020-11-30 00:24

How can this test fail?

[TestMethod]
public void Get_Code()
{
    var expected = new List();
    expected.A         


        
7条回答
  •  孤城傲影
    2020-11-30 00:54

    this test compares a date input, checks if its a leap year, if so, outputs 20 leap years from the inputted date, if not, outputs the NEXT 20 leap years, myTest.Testing refers to the myTest instance which in turn calls the values from a List called Testing containing the calculated values required. part of an exercise I had to do.

    [TestMethod]
            public void TestMethod1()
            {
                int testVal = 2012;
                TestClass myTest = new TestClass();
                var expected = new List();
                expected.Add(2012);
                expected.Add(2016);
                expected.Add(2020);
                expected.Add(2024);
                expected.Add(2028);
                expected.Add(2032);
                expected.Add(2036);
                expected.Add(2040);
                expected.Add(2044);
                expected.Add(2048);
                expected.Add(2052);
                expected.Add(2056);
                expected.Add(2060);
                expected.Add(2064);
                expected.Add(2068);
                expected.Add(2072);
                expected.Add(2076);
                expected.Add(2080);
                expected.Add(2084);
                expected.Add(2088);
                var actual = myTest.Testing(2012);
                CollectionAssert.AreEqual(expected, actual);
            }
    

提交回复
热议问题