我一直在尝试使用ASSERT_EQ和EXPECT_EQ的断言,
ASSERT_EQ(队列_->尺寸(),6);
即使使用此
ASSERT_EQ(6,6);
然而,我遇到了这个编译器错误,我搜索到的任何地方似乎都没有人面对 这个问题。
/tmp/cczZfMaq.o:在函数testing::AssertionResult testing::internal::EqHelper<false>::Compare<char, char>(char const*, char const*, char const&, char const&)':
/usr/include/gtest/gtest.h:1485: undefined reference to
中测试:: AssertionResult testing :: internal :: CmpHelperEQ(char const *,char const *,char const&amp;,char const&amp;)&#39;
collect2:错误:ld返回1退出状态
make: * [priority_queue_test.out]错误1
完整测试文件:
//Include the class which you would like to test #include "priority_queue.h" //Include the google c++ test framework #include #include #include //use the namespace for the testing class using namespace algorithms; using namespace containers; namespace{ //Test Fixture Class //multple tests in a test case shared common objects and subroutines class PriorityQueueTest : public ::testing::Test{ protected: PriorityQueueTest(){ } virtual ~PriorityQueueTest(){ } virtual void SetUp(){ queue_ = new PriorityQueue(1000); } virtual void TearDown(){ } PriorityQueue *queue_=NULL; }; TEST_F(PriorityQueueTest,CheckAllMemberInitSuccessfully){ //ASSERT is a critcal assertion which will fail the test program ASSERT_TRUE(queue_!=NULL) capacity()==1000) capacity(); } TEST_F(PriorityQueueTest,CheckIfItemsAreEnqueueCorrectly){ //test cases queue_->Enqueue(0,0); queue_->Enqueue(1,1); queue_->Enqueue(6,6); queue_->Enqueue(5,5); queue_->Enqueue(3,3); queue_->Enqueue(2,2); ASSERT_EQ('a','a'); } }//namespace int main(int argc, char *argv[]){ ::testing::InitGoogleTest(&argc,argv); return RUN_ALL_TESTS(); }