Reputation: 47
Trying to test something with NUnit 3. I have a Country
object that I'm trying to test out.
[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");
}
Keep getting an error saying no suitable constructor was found. Any help would be appreciated.
Upvotes: 0
Views: 2752
Reputation: 2199
Cosmin Cretu is correct. In NUnit v3, You need to add default parameter-less constructor for test fixture, 'Country'. Add it.
public Country() { }
Possible duplicate of this case, Nunit test gives result OneTimeSetUp: No suitable constructor was found
Upvotes: 0