2009-07-09 24 views
4

你怎麼做等價的:如何在C++/CLI NUnit測試中使用ExpectedException?

[Test, ExpectedException(typeof(ArgumentOutOfRangeException))] 
void Test_Something_That_Throws_Exception() 
{ 
    throw gcnew ArgumentOutOfRangeException("Some more detail"); 
} 

...在C++(例子中有C#)?據我所見,NUnit的C++實現沒有typeof()函數。

回答

7

爲了避免別人狩獵適合所有年齡段試圖找到它,這裏的解決方案:

[Test, ExpectedException(ArgumentOutOfRangeException::typeid)] 
void Test_Something_That_Throws_Exception() 
{ 
    throw gcnew ArgumentOutOfRangeException("Some more detail"); 
} 

只需使用異常的::typeid :-)

相關問題