如何对从具有参数化构造函数的基类继承的类执行 Nunit 测试 [英] How to perform Nunit testing for a class inherting from a base class with parameterised constructor

查看:61
本文介绍了如何对从具有参数化构造函数的基类继承的类执行 Nunit 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

namespace TestBI
{
 [TestFixture]
 class ClassChild:ClassParent
 {
    public ClassChild(DataRow row, string name): base(row, detail) { }
    [Test]
    public void Test()
    {
        DataRow dr = new DataRow();
        dr[0] = 1;
        dr[1] = "ram"  
        ClassChild ch = new ClassChild(dr,"student");

        :
        :
        :
        Assert.AreEqual(string1,string2);
     }

 }
}

当我运行测试时,我收到错误消息找到了 TestBI.ChildClass.Test 合适的构造函数"

When I run the test,i get an error as "TestBI.ChildClass.Test suitable constructor was found"

我需要如何将这里的参数传递给子类?

How do i need to pass parameters here to child class?

推荐答案

为您的测试类提供零参数构造函数.如果它调用超类的多参数构造函数就可以了,只要它提供了适当的参数即可.

Provide a zero argument constructor for your test class. It is fine if it calls a multiple argument constructor of the superclass, as long as it provides it with proper arguments.

这篇关于如何对从具有参数化构造函数的基类继承的类执行 Nunit 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆