Nunit TestFixtureData未运行测试
问题描述:
我有一个Nunit TestFixtureData测试夹具。
在visual studio测试资源管理器中,测试被标记为“未运行测试”。我想让他们工作。我想让他们作为红色/绿色测试运行。Nunit TestFixtureData未运行测试
我有Foo Factory throw没有执行expirs这些测试运行,并显示不工作。
我有其他TestFixtureData具有测试和TestCase,他们工作正常。
我不想让逻辑通过测试,我知道应该是什么。
在测试资源管理器上,我可以剖析测试,并得到“路径中存在非法字符”。在输出中。不确定这是否相关。
/// <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();
}
答
查尔感谢您指出了我。
NUnit的不喜欢的GUID的性能和最大努力把它传递字符串,然后使用它们 所以我所做的更改之前使它们的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);
}
您的代码对我来说没有意义。 FooTestFixture的构造函数接受一个Foo和一个guid,但是你在TestFixtureAttribute中传入一个Type和一个字符串。 NUnit会简单地决定它根本不能使用这个类,并将其标记为无效。由于测试浏览器不报告有关类的任何信息(仅限于方法),因此在其下运行时,错误可能会消失。使用NUnit控制台运行程序运行可能会告诉您该灯具无效。 – Charlie