玩转Google单元测试框架gtest系列之七:深入解析gtest

发表于:2010-4-12 14:54

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:CoderZh    来源:www.cnblogs.com/coderzh

  哦?TestInfo也有一个impl?看来我们之前漏掉了点东西,和UnitTest很类似,TestInfo内部也有一个主管各种实现的类,那就是TestInfoImpl,它在TestInfo的构造函数中创建了出来(还记得前面讲的TestInfo的创建过程吗?):

TestInfo::TestInfo(const char* test_case_name,
                   
const char* name,
                   
const char* test_case_comment,
                   
const char* comment,
                   
internal::TypeId fixture_class_id,
                   
internal::TestFactoryBase* factory) {
    impl_ 
= new internal::TestInfoImpl(this, test_case_name, name,
                                     test_case_comment, comment,
                                     fixture_class_id, factory);
}

  因此,案例的执行还得看TestInfoImpl的Run()方法,同样,我简化一下,只列出关键部分的代码:

void TestInfoImpl::Run() {

    // ...

    UnitTestEventListenerInterface* const result_printer =
        impl
->result_printer();
    result_printer
->OnTestStart(parent_);
   
// 开始计时
   
const TimeInMillis start = GetTimeInMillis();

    Test* test = NULL;

    __try {
       
// 我们的对象工厂,使用CreateTest()生成Test对象
        test = factory_->CreateTest();
    } __except(
internal::UnitTestOptions::GTestShouldProcessSEH(
        GetExceptionCode())) {
        AddExceptionThrownFailure(GetExceptionCode(),
                              
"the test fixture's constructor");
       
return;

    }

    // 如果Test对象创建成功

    if (!Test::HasFatalFailure()) {

        // 调用Test对象的Run()方法,执行测试案例

        test->Run();
    }

   
// 执行完毕,删除Test对象
    impl->os_stack_trace_getter()->UponLeavingGTest();
    delete test;
    test 
= NULL;

    // 停止计时
    result_.set_elapsed_time(GetTimeInMillis() - start);
    result_printer->OnTestEnd(parent_);

}

《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号