[英]Nunit TestFixtureData not running tests
我有一個Nunit TestFixtureData測試夾具。
在Visual Studio測試資源管理器中,這些測試被標記為“未運行測試”。 我想讓他們工作。 我想讓它們作為紅色/綠色測試運行。
我讓Foo Factory拋出了這些測試運行時未實現的求和運算,並且顯示不起作用。
我還有其他具有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();
}
查爾斯感謝您向我指出。
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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.