为什么我的5个测试中只有2个在我的Google C ++测试框架上运行

时间:2014-12-05 22:38:07

标签: c++ googletest

这是文件

#include <gtest/gtest.h>

#include <libLoam/c++/LoamStreams.h>
#include "../DateParser.h"

using namespace oblong::sluice;

TEST(DateParser, TestDefaultFormat)
{ DateParser parser;
  float64 when;
  EXPECT_EQ (OB_OK, parser . Parse ("12345.0", when));
  EXPECT_FLOAT_EQ (12345.0, when);
}

TEST(DateParser, TestYMDStuff)
{ DateParser parser;
  parser . AppendDateFormat ("%Y-%m-%d %H:%M:%S");
  float64 when;
  EXPECT_EQ (OB_OK, parser . Parse ("2011-11-14 19:12:21", when));
  const float64 expected = 1321297941.0;
  EXPECT_FLOAT_EQ (expected, when);
  EXPECT_FLOAT_EQ (0, when - expected);
} 

TEST(DateParser, TestJavaStringStuff)
{ DateParser parser;
  parser . AppendDateFormat ("%Y-%m-%dT%H:%M:%SZ");
  float64 when;
  EXPECT_EQ (OB_OK, parser . Parse ("2011-09-18T09:49:47Z", when));
  const float64 expected = 1316339387.0;
  EXPECT_FLOAT_EQ (expected, when);
  EXPECT_FLOAT_EQ (0, when - expected);
}

TEST(DateParser, TestAM/PMStuff)
{ DateParser parser;
  parser . AppendDateFormat ("%Y-%m-%d %I:%M:%S%p");
  float64 when;
  EXPECT_EQ (OB_OK, parser . Parse ("2011-11-14 10:12:21AM", when));
  const float64 expected = 1321265541.0;
  EXPECT_NEAR (when, expected, 1) << "Time should be close to expected " << (when - expected);
}

TEST(DateParser, TestTimeZoneStuff)
{ DateParser parser;
  parser . AppendDateFormat ("%Y-%m-%d %I:%M:%S%Z");
  float64 when;
  EXPECT_EQ (OB_OK, parser . Parse ("2011-11-14 10:12:21GMT", when));
  const float64 expected = 1321265541.0;
  EXPECT_NEAR (when, expected, 1) << "Time should be close to expected " << (when - expected);
}

TEST(DateParser, TestOtherTimeZoneStuff)
{ DateParser parser;
  parser . AppendDateFormat ("%Y-%m-%d %I:%M:%S%z");
  float64 when;
  EXPECT_EQ (OB_OK, parser . Parse ("2011-11-14 10:12:21+0900", when));
  const float64 expected = 1321297941.0;
  EXPECT_NEAR (when, expected, 1) << "Time should be close to expected " << (when - expected);
}

然而,当我尝试测试时,它只执行前2个测试(TestDefaultFormat和TestYMDStuff)。更糟糕的是,如果我删除一个测试,那么它只会测试1(正确),但如果我在删除的测试中添加回来,它就不再测试它了。因此,如果我删除了TestYMDStuff,编译并运行它,它只会测试第一个。然后,如果我在TestYMDStuff中添加它仍然只运行第一个,更不用说我在那之后添加的任何新测试。

这可能是什么???????我的语法不正确吗?

1 个答案:

答案 0 :(得分:0)

AH HA。答案是,你不能拥有测试的标题。我的一个测试名为TestAM / PMStuff。将其更改为TestAMPMStuff修复了所有问题。