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

后端 未结 8 1859
后悔当初
后悔当初 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:43

    Just create the list inside the method instead, like this:

    public void Add_WithOneNumber_ReturnsNumber()
    {
        var result = CalculatorLibrary.CalculatorFunctions.Add(new List<int>{1});
    
        Assert.AreEqual(1, result);
    }
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题