【发布时间】:2018-05-03 08:51:25
【问题描述】:
尝试使用 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");
}
不断收到错误消息,提示找不到合适的构造函数。任何帮助,将不胜感激。
【问题讨论】:
-
你在哪一行得到错误?
-
一旦遇到 CountryTest() 方法@Neijwiert
-
也许只是复制并粘贴确切的错误消息,因为“一旦它遇到 CountryTest() 方法”不是很有帮助
-
也许你需要一个空的构造函数?公共国家()?