无法运行gtest(测试装置)

时间:2019-05-23 16:56:32

标签: c++ testing googletest fixtures

我正在尝试使用测试装置练习一些简单的gtest,但是以某种方式我不断收到错误消息,例如说我在运行catkin_make run_tests时未声明测试。错误如下:

:28:19: error: ‘countingtest1’ has not been declared
 Test_F(counttest, countingtest1) {

:28:32: error: ISO C++ forbids declaration of ‘Test_F’ with no type [-fpermissive]
 Test_F(counttest, countingtest1) {

:14:7: note:   because the following virtual functions are pure within ‘counttest’:
 class counttest : public testing::Test {

/usr/include/gtest/gtest.h:422:16: note:    virtual void testing::Test::TestBody()
   virtual void TestBody() = 0;

Makefile:186: recipe for target 'run_tests' failed
make: *** [run_tests] Error 2

Invoking "make run_tests -j4 -l4" failed

这是我的代码:

'''C ++

#include "ros/ros.h"
#include "gtest/gtest.h"
using namespace std;
class counting {
public:
    int addcount() {
        static int count = 0;
        cout << count << " ";
        count += 1;
        return count;
    }
};

class counttest : public testing::Test {
    public:
        counting counting1;
        int num = 0;
        virtual void SetUp(){
            counting counting1;
        }

        virtual void startcounting(){
            for (int i=0; i<5; i++)
                int num = counting1.addcount();
        }
};

Test_F(counttest, countingtest1) {
    int num = 0;
    EXPECT_EQ(num,5);
}

int main(int argc, char **argv) {
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}

'''

0 个答案:

没有答案