2015-10-06 172 views
0

我只是在新的解決方案中設置了一個新的(本地)單元測試。但是,即使示例程序不起作用,如果我添加一個斷言。它編譯沒有問題,並且默認生成(空)測試成功。但是,當我添加一個簡單的斷言時,它會失敗,錯誤代碼爲C0000005。Visual Studio(2013)單元測試失敗C0000005

這可能與similar issue有關,但我甚至沒有連接某個庫,因此無法使用建議的解決方案。

測試看起來是這樣的:

#include "stdafx.h" 
#include "CppUnitTest.h" 

using namespace Microsoft::VisualStudio::CppUnitTestFramework; 

namespace Test_Native 
{  
TEST_CLASS(UnitTest1) 
{ 
public: 

    TEST_METHOD(TestMethod1) 
    { 
     Assert::AreEqual(1, 1, L"message", LINE_INFO()); // Without this line everything is fine 
     // TODO: Your test code here 
    } 

}; 
} 

回答

1

這是一個known bug。不幸的是,微軟認爲這是「不會修復」。

總之,有兩種解決方法:

編譯在釋放模式的實際項目,並在調試模式下的測試項目。 將所有可測試函數外包給靜態庫項目。