尝试用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");
}
继续收到错误消息,说明找不到合适的构造函数。任何帮助,将不胜感激。
答案 0 :(得分:0)
Cosmin Cretu是正确的。在NUnit v3中,您需要为测试夹具添加默认的无参数构造函数,“Country”。添加它。
public Country() { }
此案例的可能重复,Nunit test gives result OneTimeSetUp: No suitable constructor was found