c#xunit成员数据两次获取数据

时间:2016-03-03 16:28:50

标签: c# xunit xunit.net

我使用xUnit进行简单的测试项目。当我在GetTestData方法中返回类的新instans(new LinkConfig)时。 因此,在调试时,GetTestData方法在所有测试运行之前调用两次。但是如果我返回字符串而不是类的新instand,它的工作正常。

[Theory]
[MemberData(nameof(GetTestData))]
public void Test(LinkConfig config)
{ 
//Arrange
var url = config.Url;

//Act & Assert 
Assert.Equal("http://google.com", url); 
}

public static IEnumerable<object[]> GetTestData()
{  
var config = new LinkConfig { Url = "http://google.com" }; 
yield return new object[] { config }; 
}

0 个答案:

没有答案