【问题标题】:Boost.Test application debuggingBoost.Test 应用程序调试
【发布时间】:2011-03-30 01:15:46
【问题描述】:

在 VS2010 (VS2008) 中调试 C++ Boost.Test 应用程序时,如何让调试器在 Boost.Test 断言失败点处停止?

【问题讨论】:

    标签: c++ unit-testing visual-studio-2010 boost


    【解决方案1】:

    我自己没有尝试过,但理论上你可能想在check_impl function(在 boost_unit_test_library 源中)的某个地方设置一个断点,可能是在其最终案例语句的非 PASS 情况下。

    在实践中,我总是发现自己只是再次运行测试(或使用 --run_test=... 选择的特定问题测试),并在有问题的检查上设置断点。

    请注意,失败的BOOST_REQUIRE 会导致抛出异常,因此如果您在调试选项中启用 VS 的 break-on-C++-exceptions 会很好地中断这些异常(但不是 BOOST_CHECKs,它只会返回并继续)。

    【讨论】:

    • 谢谢。我还发现遵循 Boost.Test 文档的“Microsoft Visual Studio .NET 用户特定”一章中描述的过程很有用。它允许在验证失败的地方手动设置断点。
    【解决方案2】:

    按照@timday 的建议,我在check_impl() 中设置了断点。

    这是 Boost 1.57.0 的摘录,文件 boost/test/impl/test_tool.ipp,第 355 到 373 行:

    switch( tl ) {
    case PASS:
        framework::assertion_result( true );
        return true;
    
    case WARN:
        return false; // ADD BREAKPOINT HERE
    
    case CHECK:
        framework::assertion_result( false );
        return false; // ADD BREAKPOINT HERE
    
    case REQUIRE:
        framework::assertion_result( false );
    
        framework::test_unit_aborted( framework::current_test_case() );
    
        throw execution_aborted(); // ADD BREAKPOINT HERE
    }
    

    【讨论】:

    • 这似乎不适用于 boost 1.63。 test_tool.ipp 中的错误报告似乎发生在一个单独的线程中,或者以某种方式发生在最后,当所有测试都已被检查时。我想在断言发生时停止。
    【解决方案3】:

    assertion.hpp

    模板类 binary_expr:

    assertion_result            evaluate( bool no_message = false ) const
        {
            assertion_result const expr_res( value() );
            if( no_message || expr_res )
                return expr_res;   <<<<<<<<  SUCCESS
    
    BRK        wrap_stringstream buff;
            report( buff.stream() );
    
            return tt_detail::format_assertion_result( buff.stream().str(), expr_res.message() );
        }
    

    【讨论】:

      猜你喜欢
      • 2021-07-25
      • 2010-12-16
      • 2012-12-10
      • 2010-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多