C#, NUnit Assert in a Loop

后端 未结 3 1116
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-13 09:18

I have a school assignment where I need to create a data-driven style of NUnit testing. Using the below code, I am able to get the data from the database, but everytime an \'Ass

3条回答
  •  感动是毒
    2021-02-13 10:19

    Beside using the RowTest extension as suggested by Sam Holder you can also use the TestCaseAttribute for this:

    [TestFixture]
    public class TestCaseSample 
    {      
        [TestCase(1)]
        [TestCase(2)]
        [TestCase(3)]
        [TestCase(4)]
        [TestCase(5)]
        [TestCase(6)]
        public void GetProductById(int productId)
        {           
            Assert.That(pm.GetProductById(productId),Is.Not.Null);
        } 
    } 
    

提交回复
热议问题