i installed the gtest using apt-get install libgtest-dev
and i am trying to check if that is working or not.
so i make simple code for testing in eclipse.
but there are error,
undefined reference to 'testing::Test::~Test()'
undefined reference to 'testing::Test::Test()'
conversely if i change the inheritance at the ATest class as protected the error disappear but
the other error occur
testing::Test is inaccessible base of 'ATest_AAA_Test'
what is wrong ?
#include <iostream>
#include <gtest/gtest.h>
class A{
public:
int a;
A(int a){this->a = a;}
A(){}
~A(){}
int getA(){return a;}
void setA(int a){this->a = a;}
};
class ATest : public ::testing::Test{
public:
virtual void SetUp(){
a1 = A(1);
a2 = A(2);
a3 = A(3);
}
virtual void TearDwon(){}
A a1;
A a2;
A a3;
};
TEST_F(ATest, AAA){
EXPECT_EQ(1, a1.getA());
EXPECT_EQ(2, a2.getA());
EXPECT_EQ(3, a3.getA());
}
int main(int argc, char **argv){
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
If you have a broken test that you cannot fix right away, you can add the DISABLED_ prefix to its name. This will exclude it from execution. This is better than commenting out the code or using #if 0 , as disabled tests are still compiled (and thus won't rot).
Google Test is not header-only: there are libraries to build. So, as a Visual Studio user, you have essentially two options.
I know this sounds obvious but my psychic debugging skills tell me you forgot to add -lgtest
after your object file name when you linked your final binary.
Installing libgtest-dev
does not install any of the gtest binaries.
It simply installs the googletest source package on your system - headers
under /usr/include/gtest
and source files under /usr/src/gtest
,
where you could proceed to build it with cmake
or GNU autotools
if you want.
There is no binary package for googletest in ubuntu/debian software channels
(or elsewhere that I know of). The normal practice is to
download the source archive,
extract it and use binaries built by yourself. The README
in the
source package gives guidance on building and using the library.
There is normally no purpose in performing a system install of the source package, as you have done.
The linkage error you have encountered:
undefined reference to 'testing::Test::~Test()
has nothing to do with your code: it occurs because you are not
linking libgtest
, and you cannot link it because it is not installed
by libgtest-dev
and you have not built it yourself.
This linkage error disappears when you change the code in a way that introduces a compilation error, because if compilation fails then linkage does not happen.
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