[英]NUnit- No Suitable Constructor was Found
嘗試使用NUnit 3進行測試。我有一個Country
對象,我正在嘗試進行測試。
[TestFixture]
public class Country : IComparable
{
private String countryName;
private float GDP;
private float inflation;
private float tradeBalance;
private float HDIRanking;
private List<String> tradePartners;
private String displayPartnersInTable; //used to display trade partners in Data table, turns list into string with commas to be displayed nicely
Country c;
public Country(String countryName, float GDP, float inflation, float tradeBalance, float HDIRanking, List<String> tradePartners)
{
this.countryName = countryName;
this.GDP = GDP;
this.inflation = inflation;
this.tradeBalance = tradeBalance;
this.HDIRanking = HDIRanking;
this.tradePartners = tradePartners;
}
[SetUp]
public void Init()
{
List<String> l = new List<string>();
l.Add("UK");
Country c = new Country("Malta", (float)1.2, (float)2.3, (float)3.2, 1, new List<string>() { "UK" });
}
[Test]
public void CountryTest()
{
Assert.AreEqual("Malta", c.countryName, "Wrong country");
}
不斷收到錯誤消息,提示找不到合適的構造函數。 任何幫助,將不勝感激。
Cosmin Cretu是正確的。 在NUnit v3中,您需要為測試治具“ Country”添加默認的無參數構造函數。 添加它。
public Country() { }
這種情況下可能重復, Nunit測試給出結果OneTimeSetUp:找不到合適的構造函數
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.