Reputation: 25076
See the below test fixture:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
/// <summary>
/// Tests relating to Harry Potter
/// </summary>
[TestFixture("Dumbledore")]
public class HarryPotterTests
{
public string Name;
public HarryPotterTests(string personName)
{
Name = personName;
}
[Test]
public void Test()
{
Console.WriteLine(Name);
}
}
What I'm trying to achieve is to see how parameterised test fixtures work. I haven't used them before so this is my first stab at it.
It looks OK to me. Constructor with a string, and passing in a string in the actual test fixture attribute. It compiles. Test simply writes it out to a console window.
The test however fails with this message:
No suitable constructor was found
Am I missing something blindly obvious?
No matter where I put a breakpoint, nothing is hit, so it is failing very early on.
Upvotes: 13
Views: 22111
Reputation: 3
Just in case it helps someone else. In my case, I was using TestFixtureSource, and a function to build the combinations for the different TestFixtures. Turns out that the number of element in the array did not match the number of parameters for the constructor. (I forgot the -1)
Upvotes: 0
Reputation: 3413
Fairly obvious, but can also happen if the test's constructor is not public.
Upvotes: 2
Reputation: 1133
I had this problem. It was caused by the constructor throwing an error, rather than any issue with the constructor parameters. The error message was misleading in my case.
Upvotes: 20
Reputation: 2088
I experienced this problem - running a Test class under NUnit and via the Resharper 8.
However, if I changed the TestFixture declaration from this form
[TestFixture("CategoryName")]
to this form:
[TestFixture(Category="CategoryName")]
then they worked... this also improved things via NUnit - but as it happens for my particular tests I have connectionString and Entity Framework issues which Resharper helps with and NUnit does not - but essentially I believe NUnit is happier with the latter syntax.
Upvotes: 14
Reputation: 6482
Check if your constructor has any logic that might be failing. It turns out I had a call in the Constructor (bad!) that should have been in TestFixtureSetUp
. In Resharper this is the the default error message with parameterized test fixtures if anything throws an exception in the constructor.
Upvotes: 2
Reputation: 25076
This particular problem is a bug in JustCode's NUnit Test Runner. Re-running this with Resharper 7's NUnit Runner and the NUnit GUI, both pass.
Upvotes: 4
Reputation: 15981
Your test class is perfectly valid and returns Passed when running NUnit 2.6 and .NET 4, both with the NUnit GUI and the Resharper 7 test runner.
The error you are seeing occurs when the types of the arguments in the TestFixture
constructor does not match the types of the test class constructor. For example, if I add the line:
[TestFixture(10)]
I will get the following error in the NUnit GUI:
ParameterizedNunit.HarryPotterTests(10).Test:
ParameterizedNunit.HarryPotterTests does not have a suitable constructor
Upvotes: 7