Sto iniziando a utilizzare googlemock con googletest ma sto ottenendo un'eccezione SEH che non riesco a capire.SEH eccezione quando si utilizza googlemock
Il messaggio di errore è:
unknown file: error: SEH exception with code 0xc0000005 thrown in the test body.
Ho letto alcune domande simili su SO e altrove, ma sono ancora trovare una risposta per un semplice esempio tale.
vale a dire questo sta accadendo sul mio codice reale, ma ho anche riprodotto l'errore nel semplicissimo esempio di seguito. Sto costruendo con MSVC2008.
codice che riproduce l'errore:
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include <iostream>
using testing::Exactly;
class Production
{
public:
virtual ~Production() {};
virtual void fn() = 0;
};
class ProductionCode : public Production
{
public:
virtual ~ProductionCode() {};
void fn()
{
std::cout << "CALLED ProductionCode::fn" << std::endl;
}
};
class MockProduction : public Production
{
public:
virtual ~MockProduction() {};
MOCK_METHOD0(fn, void());
};
class ProductionUser
{
public:
void methodUnderTest(Production *p)
{
p->fn();
}
};
TEST(ProductionTest, CallTheProductionFunction) {
ProductionCode p;
ASSERT_NO_THROW(p.fn());
}
TEST(ProductionTest, CallTheMethodUnderTest) {
Production* p = new ProductionCode;
ProductionUser u;
ASSERT_NO_THROW(u.methodUnderTest(p));
delete p;
}
TEST(ProductionTest, CallTheMethodUnderTestWithMock) {
MockProduction m;
EXPECT_CALL(m, fn())
.Times(Exactly(1));
ProductionUser u;
ASSERT_NO_THROW(u.methodUnderTest(&m));
}
la mia uscita di prova dalla console:
[==========] Running 3 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 3 tests from ProductionTest
[ RUN ] ProductionTest.CallTheProductionFunction
CALLED ProductionCode::fn
[ OK ] ProductionTest.CallTheProductionFunction (4 ms)
[ RUN ] ProductionTest.CallTheMethodUnderTest
CALLED ProductionCode::fn
[ OK ] ProductionTest.CallTheMethodUnderTest (2 ms)
[ RUN ] ProductionTest.CallTheMethodUnderTestWithMock
unknown file: error: SEH exception with code 0xc0000005 thrown in the test body.
[ FAILED ] ProductionTest.CallTheMethodUnderTestWithMock (0 ms)
[----------] 3 tests from ProductionTest (10 ms total)
[----------] Global test environment tear-down
[==========] 3 tests from 1 test case ran. (13 ms total)
[ PASSED ] 2 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] ProductionTest.CallTheMethodUnderTestWithMock
1 FAILED TEST
.\simple.cpp(59): ERROR: this mock object (used in test ProductionTest.CallTheMe
thodUnderTestWithMock) should be deleted but never is. Its address is @000000000
014F800.
ERROR: 1 leaked mock object found at program exit.
Press any key to continue . . .
Sto usando il mio propria funzione principale come segue:
#include "gtest/gtest.h"
#include "gmock/gmock.h"
int main(int argc, char** argv) {
// The following line must be executed to initialize Google Mock
// (and Google Test) before running the tests.
::testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();
}
Sono indovinando che sto facendo un errore piuttosto semplice qui, qualcuno può vedere dove sto andando male? Grazie!
[originale a cura di rendere il codice di uscita partita & console]
È questo il codice effettivo che genera quell'output? Non vedo 'ProductionTest.CallTheUseOnProductionUser()' e due 'ProductionTest.CallTheMethodUnderTest()' s. – metal
@metal È lì. 'TEST (ProductionTest, CallTheMethodUnderTest)' è una macro che specifica il test unitario che viene automaticamente chiamato buy the testing framework. –
Vedo quel test elencato due volte e nessun segno di 'CallTheUseOnProductionUser'. Devo ammettere che non ho familiarità con GoogleMock, ma ho utilizzato molti altri framework di test. Mi sto perdendo qualcosa? – metal