c# - NUnit - 没有找到合适的构造函数
问题描述
试图用 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:没有找到合适的构造函数
推荐阅读
- c - 为什么我的“for”循环只运行了两次?
- python - 关于矩阵乘法的一些问题?
- c++ - 类型转换问题:以整数而不是浮点/类型返回
- javascript - Firebase(Firestore)获取参考值异步 - ReactJS
- python - 是否可以按自定义顺序使用“输入变量”
- javascript - 为什么在 Angular 中使用插件后 html 不显示?
- javascript - Gatsby/React:自动替换某个特定的第 n 代后代的所有元素和
元素 - c# - 如何在 C# 的不同线程中同步从 MemoryString 写入文件?
- sql - SQL Server存储过程计算两个表中的匹配记录并将数字插入另一个表
- python - 等效于 Python 中的“qt”R 函数