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

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

    use array as parameter new [] {1, 2} for the Testcases and convert it to List inside the test method numbers.ToList().

    using System.Linq
    ...
    
    [TestCase(new [] {1}, 1)]
    [TestCase(new [] {1, 2}, 3)]
    [TestCase(new [] {1, 2, 3}, 6)]
    public void Return_sum_of_numbers(int[] numbers, int expectedSum)
    {
        var sum = CalculatorLibrary.CalculatorFunctions.Add(numbers.ToList());
    
        Assert.AreEqual(expectedSum, sum );
        // much cooler with FluentAssertions nuget:
        // sum.Should.Be(expectedSum);
    }
    

提交回复
热议问题