简体   繁体   中英

Nunit TestFixtureData not running tests

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();
    }

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM