2010-03-12 16 views
2

我試圖利用NUnit 2.5中引入的TheoryAttribute。一切只要參數是一個定義類型的正常工作:爲什麼NUnit在理論中使用泛型時忽略數據點

[Datapoint] 
public double[,] Array2X2 = new double[,] { { 1, 0 }, { 0, 1 } }; 

[Theory] 
public void TestForArbitraryArray(double[,] array) 
{ 
    // ... 
} 

它不工作,當我使用泛型:

[Datapoint] 
public double[,] Array2X2 = new double[,] { { 1, 0 }, { 0, 1 } }; 

[Theory] 
public void TestForArbitraryArray<T>(T[,] array) 
{ 
    // ... 
} 

NUnit的提出警告說No arguments were provided。這是爲什麼?

+0

我報道這個行爲到NUnit的開發者的錯誤(https://bugs.launchpad.net/nunitv2/+bug/537914)和查理·普爾就開在這個問題上的NUnit-討論(HTTPS的討論: //groups.google.com/group/nunit-discuss/browse_thread/thread/6d16b06ec18ca19f)。 – 2010-07-21 12:54:27

回答

2

我認爲這是因爲Datapoints必須將類型與DatapointAttribute匹配。從NUnit help上數據點:

當理論被加載,NUnit的通過使用任何字段與DatapointAttribute註釋的參數相同類型的會爲每個其參數的參數。此外,還使用了使用DatapointsAttribute註釋的所需類型的數組元素。