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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With