Fields in the test class are not visible. Google Test, CLion


I am writing unit test in CLion with Google Test
Test.h
1
2
3
4
5
6
7
8
9
#include <gtest/gtest.h>

class CycleTest : public ::testing::Test {
protected:
    void SetUp() {
        cycle = 0;
    };
    int cycle;
};


Test.cpp
1
2
3
4
#include "CycleTest.h"
    TEST(CycleTest, cycleTest) {
    cycle++;
}


I got a compilation error in cpp file:
error: use of undeclared identifier 'cycle'

Is it something with IDE, or I improperly use GT?


Last edited on
To use a test fixture, replace the macro TEST with TEST_F. The interface is identical:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <gtest/gtest.h>

class CycleTest : public ::testing::Test {
 protected:
  void SetUp() {
    cycle = 0;
  };
  int cycle;
};

TEST_F(CycleTest, cycleTest) {
  cycle++;
}

int main(int argc, char **argv) {
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}
Last edited on
Topic archived. No new replies allowed.