Nunit TestFixtureData没有运行测试

时间:2017-02-24 15:25:33

标签: c# unit-testing nunit

我有一个Nunit TestFixtureData,测试夹具 在visual studio test explorer中,测试被标记为Not Run Tests。我想让他们工作。我想让它们作为红色/绿色测试运行。

我有Foo Factory抛出没有实现expiations这些测试运行,并显示不工作。

我有其他具有Test和TestCase的TestFixtureData,它们工作正常。

我不希望逻辑通过测试,我知道应该是什么。

在测试资源管理器上,我可以对测试进行概要分析,并得到“路径中的非法字符”。在输出中。不确定这是否相关。

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

        }
    }
}

让FooFactory干脆做。我知道这会使测试失败,但测试没有运行

    public static Foo Create(Guid fooId )
    {
        return new Foo();
    }

    public static Foo Edit Edit(Foo foo)
    {
        return new Foo();
    }

1 个答案:

答案 0 :(得分:1)

查理谢谢你指出我。

Nunit不喜欢guids作为属性,最好将它们作为字符串传递,然后在使用它们之前使它们成为guid 所以我做的改变是

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

    }
}

}

并且测试夹具变得

public FooTestFixture(Foo foo, string fooId)
{
    this.foo = foo;
    this.fooId = new Guid(fooId);
}