我有一个学校作业,需要创建一种基于数据驱动的 NUnit 测试风格。使用下面的代码,我能够从数据库中获取数据,但是每次“Assert”调用失败时,测试都会停止。
是否有任何方法可以将循环的结果显示为六个不同的测试(考虑到数据库中有六行)?
namespace TestClasses
{
[TestFixture]
public class TestingClass : ConnectionClass
{
private ProductManagement pm;
[TestFixtureSetUp]
public void CreateTestClass()
{
pm = new ProductManagement();
}
[TestCase]
public void GetProductDetailsTest()
{
SqlDataAdapter da = new SqlDataAdapter("Select * From GetProductDetailsTest;", Connection);
Database1DataSet.GetProductDetailsTestDataTable dt = new Database1DataSet.GetProductDetailsTestDataTable();
da.Fill(dt);
foreach (Database1DataSet.GetProductDetailsTestRow dr in dt.Rows)
{
if (pm.GetProductById(dr.productId) == null)
Assert.Fail("Id of test case: " + dr.id + ", Product id of failure: " + dr.productId);
}
}
}
}
我需要的是,如果可能的话,NUnit能够显示3个通过的测试和3个失败的测试!非常感谢您的帮助,谢谢!:)