【问题标题】:NUnit- No Suitable Constructor was FoundNUnit - 没有找到合适的构造函数
【发布时间】: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() 方法”不是很有帮助
  • 也许你需要一个空的构造函数?公共国家()?

标签: c# nunit


【解决方案1】:

Cosmin Cretu 是正确的。在 NUnit v3 中,您需要为测试夹具“Country”添加默认的无参数构造函数。添加它。

public Country() { }

此案例可能重复,Nunit test gives result OneTimeSetUp: No suitable constructor was found

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-08
    • 1970-01-01
    • 2015-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-02
    相关资源
    最近更新 更多