Reputation: 1258
I have a Nunit TestFixtureData, test fixture.
The tests are getting marked as Not Run Tests, in the visual studio test explorer. I would like to get them working. I would like to get them running as red/green tests.
I have the Foo Factory throw not implemented expiations these tests run, and show not working.
I have other TestFixtureData that have Test and TestCase and they are working fine.
I am not wanting the logic to pass the tests, I know what that should be.
On the Test Explorer, I can profile the test and I get "Illegal characters in path." in the output. Not sure if this is relevant.
/// <summary>
/// This is a TestFixtureData test. See https://github.com/nunit/docs/wiki/TestFixtureData for more information
/// </summary>
[TestFixtureSource(typeof(FooTest), "FixtureParms")]
public class FooTestFixture
{
private readonly Foo foo;
private readonly Guid fooId;
public FooTestFixture(Foo foo, Guid fooId)
{
this.foo = foo;
this.fooId = fooId;
}
[Test]
public void FooId_IsSet()
{
//Arrange
//Act
var value = foo.FooId;
//Assert
Assert.AreNotEqual(Guid.Empty, value);
}
[TestCase("A")]
[TestCase("B")]
[TestCase("C")]
public void ActivityList_Contains(string activity)
{
//Arrange
//Act
var value = foo.ActivityList;
//Assert
Assert.IsTrue(value.Contains(activity));
}
}
public class FooTest
{
public static IEnumerable FixtureParms
{
get
{
var fooId = Guid.NewGuid();
var foo = new Foo() { FooId = fooId };
yield return new TestFixtureData(FooFactory.Edit(foo), fooId);
yield return new TestFixtureData(FooFactory.Create(fooId), fooId);
yield return new TestFixtureData(foo, fooId);
}
}
}
With the FooFactory simply doing. I know this would fail the tests but the tests are not running
public static Foo Create(Guid fooId )
{
return new Foo();
}
public static Foo Edit Edit(Foo foo)
{
return new Foo();
}
Upvotes: 0
Views: 1132
Reputation: 1258
Charle thanks for pointing it out to me.
Nunit doesn't like guids as properties and its best to pass them as strings, then make them guids before using them So the changes I made were
public class FooTest
{
public static IEnumerable FixtureParms
{
get
{
var fooId = "152b1665-a52d-4953-a28c-57dd4483ca35";
var fooIdGuid = new Guid(fooId);
var foo = new Foo() { FooId = fooIdGuid };
yield return new TestFixtureData(FooFactory.Edit(foo), fooId);
yield return new TestFixtureData(FooFactory.Create(fooIdGuid), fooId);
yield return new TestFixtureData(foo, fooId);
}
}
}
and the test fixture became
public FooTestFixture(Foo foo, string fooId)
{
this.foo = foo;
this.fooId = new Guid(fooId);
}
Upvotes: 1