How do I put new List {1} in an NUNIT TestCase?

后端 未结 8 1877
后悔当初
后悔当初 2020-12-13 13:12

I have the method:

public static int Add(List numbers)
    {
        if (numbers == null || numbers.Count == 0)
            return 0;

        if          


        
8条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-13 13:47

    You can't use objects only compile-time constants in data attributes. To avoid using reflection, which I find to be extremely unreadable and not at all appropriate for a test which is meant to formally describe behavior as clearly as possible, here's what I do:

        [Test]
        public void Test_Case_One()
        {
            AssertCurrency(INPUT, EXPECTED);
        }
    
        [Test]
        public void Test_Case_Two()
        {
            AssertCurrency(INPUT, EXPECTED);
        }
    
        private void AssertScenario(int input, int expected)
        {
            Assert.AreEqual(expected, input);
        }
    

    It's a few more lines, but that's only because I want clear test output. You could just as easily put them in one [Test] if you are looking for something more concise.

提交回复
热议问题