我有代碼使用boost
它看起來像文件系統交互:如何模擬提升拋出異常?
FileMigrater::migrate() const {
//stuff
try {
boost::filesystem::create_direcotry(some_path_);
} catch(const std::exception& e) {
LOG(ERROR) << "Bad stuff happened";
return MigrationResult::Failed;
}
//more stuff
}
我使用gmock
和gtest
寫爲migrate
方法的單元測試,我想編寫一個測試的情況下其中boost
引發異常。理想情況下,我想編寫一個單元測試,它看起來像(這句法將是錯誤的,因爲我在通用新的C++):
TEST_F(MyTest, boost_exception_test) {
ON_CALL(boost_mock, create_directory()).Throw(std::exception);
EXPECT_EQ(Migration::Failed, migrater.migrate());
}
的問題是,我不知道如何創建boost_mock
或者即使這是解決問題的正確方法。
我的方法:默默坐在那裏,有你的頭像捂臉每當升壓拋出這樣一個異常 – sehe