I'm testing my code with gtest.
In my code I'm using std::thread and I need to test the situation of exception.
How can I mock std functions?
I can't separate my test for two executables and I need some test to actually create std::thread and to have few tests that test the situation of exception.
Code:
[do someting]
try {
ChallengeThread = std::move(std::thread(&ChallengeListener, this));
res = SUCCESS;
} catch (const std::system_error &err) {
Log("Caught system_error with error: " + std::string(err.what()) + ". Fail to create ChallengeListener thread");
res = ERR_CREATE_THREAD;
} catch (...) {
mLogger.LogMessage("Caught ellipsis, Fail to create ChallengeListener thread");
res = ERR_CREATE_THREAD;
}
[do someting else]
Test:
EXPECT_CALL(???, thread(_, _)).Times(1).WillOnce(Throw(exception));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…