我成功地在我的小程序上建立了google测试,并创建了一个固定类。我试着测试我的类族谱中整数"start_ind_id_array_“公共成员的向量的大小。以下是代码:
class BuildgenTest : public ::testing::Test {
protected:
virtual void SetUp(){
const string pedigree_fileName("../input_files/genealogies.txt");
const string start_filename("../input_files/start");
Genealogy curGen;
curGen.ReadPedigree(pedigree_fileName.c_str());
curGen.SetStartIndividual(start_filename.c_str());
cout << curGen.start_ind_id_array_.size() <<"\n" ;
}
Genealogy curGen;
};
TEST_F(BuildgenTest,veriftest){
int number_of_starting_individuals = curGen.start_ind_id_array_.size();
EXPECT_EQ(number_of_starting_individuals,3916);
}第一个cout给了我我想要的号码,3916。但是我的测试EXPECT_EQ失败了,因为我的数组的大小现在是0,而不是我预期的3916。
知道是什么原因造成的吗?
发布于 2013-12-09 16:42:41
你在跟踪curGen。您可以在安装函数和类主体中定义它。安装程序中的版本隐藏在正文中的版本:
virtual void SetUp(){
const string pedigree_fileName("../input_files/genealogies.txt");
const string start_filename("../input_files/start");
Genealogy curGen;
^^^^^^^^^^^^^^^^^
curGen.ReadPedigree(pedigree_fileName.c_str());
curGen.SetStartIndividual(start_filename.c_str());
cout << curGen.start_ind_id_array_.size() <<"\n" ;
}https://stackoverflow.com/questions/20475675
复制相似问题