一、C++在VS2015上進行單元測試
1.創建單元測試項目;
2.包含#include "CppUnitTest.h"文件和using namespace Microsoft::VisualStudio::CppUnitTestFramework;聲明;
3.類聲明TEST_CLASS(TestCppWin)和函數聲明TEST_METHOD(CppWin_WinShareMemory);
4.如果是32位單元測試,那麼已經可以了;如果需要64位程序,選擇【測試】【測試設置】【默認處理器體系架構】選擇x64;
5.更改測試平臺爲x64,重新編譯測試;
常用的測試代碼:
Assert::AreEqual() / Assert::AreNotEqual();
Assert::AreSame() / Assert::AreNotSame();
Assert::IsTrue() / Assert::IsFalse();
Assert::IsNull() / Assert::IsNotNull();
Assert::ExpectException();
Assert::Fail();