gtest 设置拆卸 TestEnvironment - class 变量问题

gtest setup teardown TestEnvironment - issue with class variable

我有另一个 gtest,我在其中执行以下操作并且工作正常:

TEST(TEST1, TestName)
{
ClassName env;
const String original = env(Con::WorkingDir);

Con c = env;
}

但是,我希望为另一个 gtest class 设置它并在整个测试夹具中保持。但是,我收到此错误消息:

Call of an object of class type without appropriate operator or conversion functions to pointer-to-function type.

我正在查看 ,但我不确定我缺少什么。它可能使用我不熟悉的静态变量。不过,我不希望 ClassName 是静态的。

我做错了什么?

//this is intended to setup env to use in teardown.
class TestEnvironment : public ::testing::Environment {
public:
 static String getEn() {
   ClassName env;
   static const String sString = env(Con::WorkingDir);  //env has the error message here
   return sString;
 }
}

class UnitTest : public ::testing::Test
{
public:
virtual void SetUp() {
   //
}

virtual void TearDown() {
  //set env back to initial value
  getEn();
  //process env info;
}
class UnitTest : public ::testing::Test {  //can't use Environment here because of name conflict in our code, although that was used by static const variable setup in example link.
public:
 String orig;
}

class UnitTest : public ::testing::Test
{
public:
virtual void SetUp() {
   orig = code;
}

virtual void TearDown() {
  //process orig;
}

事实证明,即使我们的代码正在寻找一个 const 字符串,我们也不必将其保存为 const。