我有代码使用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