![](/img/trans.png)
[英]How to call parameterised base class constructor from parameterless derived class?
[英]How to perform Nunit testing for a class inherting from a base class with parameterised constructor
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找到了合適的構造函數”
我該如何在此處將參數傳遞給子類?
為您的測試類提供零參數的構造函數。 只要調用超類的多參數構造函數,就可以,只要它為其提供了適當的參數即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.