lundi 5 octobre 2015

Eclipse CDT and Google Test

I am learning how to use the CDT optional C/C++ Unit Test support. I try to use a testing example from this post using googletest in eclipse: how?. I added the following files to my project:

Counter.h

class Counter {  private: 
    int mCounter; public:    
    Counter() : mCounter(0) {}  
    int Increment();     
};

Counter.cpp

#include <stdio.h>
#include "Counter.h"

int Counter::Increment() {    
    return mCounter++;
}

Counter_Tests.cpp

#include "gtest/gtest.h"
#include "Counter.h"

TEST(Counter, Increment) {
      Counter c;    
      EXPECT_EQ(0, c.Increment());
      EXPECT_EQ(1, c.Increment());
      EXPECT_EQ(2, c.Increment());
}

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

I built the project and selected Run Configurations from the Run menu. I created a new launch configuration. In the C/C++ Testing tab I selected Google Test Runner.

My problem is, that I can not run the test (the Run button is inactive). The Run Configurations also has a Main tab, where is a C/C++ Application field. I put here "Debug/Counter_Tests", although the build does not produced any executable (only a Counter_Tests.o and Counter.o and the corresponding d files were generated).

I think the solution is not very complicated, being new to Eclipse I assume that I am just doing something wrong.

Aucun commentaire:

Enregistrer un commentaire