I would like to mock function that return void:
class FileDownloaderMock : public FileDownloader
{
public:
MOCK_CONST_METHOD1(downloadFile,
void(data *data_ptr));
};
in test case i would like to call this function 2 times, firstly should rise an exception and in the second times should work correctly. So my test case looks like this but doesn't work.
TEST_F(BCtrlTargetBdDownloaderTests, DownloaderShouldCorrectlyDownloadTargetBdInFirstAttempt)
{
EXPECT_CALL(m_fileDownloader, downloadFile( DataReqMatcher(l_expectedReq) ) ).Times(2)
.WillOnce(Throw(UpgradeException("Download failed") ));
}
The console output:
to few actions specified in EXPECT_CALL(m_fileDownloader, downloadFile( DataReqMatcher(l_expectedReq) ))... Expected to be called twice, but has only 1 WillOnce().
So how can I solve this puzzle? Best Regards
Your EXPECT_CALL
configuration should look like
EXPECT_CALL(m_fileDownloader, downloadFile( DataReqMatcher(l_expectedReq) ) )
.Times(2)
.WillOnce(Throw(UpgradeException("Download failed")))
.WillOnce(Return());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With