高效工作、快乐生活

发布新日志

  • gtest for xml output

    2010-05-17 14:42:39

    Google Test can emit a detailed XML report to a file in addition to its normal textual output. The report contains the duration of each test, and thus can help you identify slow tests.

    To generate the XML report, set the GTEST_OUTPUT environment variable or the --gtest_output flag to the string "xml:_path_to_output_file_", which will create the file at the given location. You can also just use the string "xml", in which case the output can be found in the test_detail.xml file in the current directory.

    If you specify a directory (for example, "xml:output/directory/" on Linux or "xml:output\directory\" on Windows), Google Test will create the XML file in that directory, named after the test executable (e.g. foo_test.xml for test program foo_test or foo_test.exe). If the file already exists (perhaps left over from a previous run), Google Test will pick a different name (e.g. foo_test_1.xml) to avoid overwriting it.

    The report uses the format described here. It is based on the junitreport Ant task and can be parsed by popular continuous build systems like Hudson. Since that format was originally intended for Java, a little interpretation is required to make it apply to Google Test tests, as shown here:


    <testsuites
    name="AllTests" ...>
    <testsuite name="test_case_name" ...>
    <testcase name="test_name" ...>
    <failure message="..."/>
    <failure message="..."/>
    <failure message="..."/>
    </testcase>
    </testsuite>
    </testsuites>
    • The root <testsuites> element corresponds to the entire test program.
    • <testsuite> elements correspond to Google Test test cases.
    • <testcase> elements correspond to Google Test test functions.

    For instance, the following program

    TEST(MathTest, Addition) { ... }
    TEST
    (MathTest, Subtraction) { ... }
    TEST
    (LogicTest, NonContradiction) { ... }

    could generate this report:

    <?xml version="1.0" encoding="UTF-8"?>
    <testsuites tests="3" failures="1" errors="0" time="35" name="AllTests">
    <testsuite name="MathTest" tests="2" failures="1"* errors="0" time="15">
    <testcase name="Addition" status="run" time="7" classname="">
    <failure message="Value of: add(1, 1)&#x0A; Actual: 3&#x0A;Expected: 2" type=""/>
    <failure message="Value of: add(1, -1)&#x0A; Actual: 1&#x0A;Expected: 0" type=""/>
    </testcase>
    <testcase name="Subtraction" status="run" time="5" classname="">
    </testcase>
    </testsuite>
    <testsuite name="LogicTest" tests="1" failures="0" errors="0" time="5">
    <testcase name="NonContradiction" status="run" time="5" classname="">
    </testcase>
    </testsuite>
    </testsuites>

    Things to note:

    • The tests attribute of a <testsuites> or <testsuite> element tells how many test functions the Google Test program or test case contains, while thefailures attribute tells how many of them failed.
    • The time attribute expresses the duration of the test, test case, or entire test program in milliseconds.
    • Each <failure> element corresponds to a single failed Google Test assertion.
    • Some JUnit concepts don't apply to Google Test, yet we have to conform. to the DTD. Therefore you'll see some dummy elements and attributes in the report. You can safely ignore these parts.

    Availability: Linux, Windows, Mac.

    本文为转载,版权归原作者所有

  • 如何使用google test进行单元测试

    2010-05-11 14:39:52

    近期需要寻找一个单元测试工具,可以在xp,win CE,symbian,android平台上运行。结果选择了,google test。目前已经可以在xp和win CE上应用。总结如下:

    【如何在winCE上使用gtest】
     
    Google's framework for writing C++ tests on a variety of platforms (Linux, Mac OS X, Windows, Cygwin, Windows CE, and Symbian). Based on the xUnit

    architecture. Supports automatic test discovery, a rich set of assertions, user-defined assertions, death tests, fatal and non-fatal failures, value- and

    type-parameterized tests, various options for running the tests, and XML test report generation.

    【在xp上使用gtest】
    1 从http://code.google.com/p/googletest/上下载gtest最新版本;
    2 用vs2008打开msvc下的sln
    3 选择平台win32,编译debug的lib库
    4 新建一个win32的带console的应用程序。在工程-属性-c/c++ - 常规 -附加包含目录"../include";
    5 连接器 - 常规 - 附加库目录"..\lib"
               输入 - 附件依赖项 gtestd.lib,回车换行添加
    6 编译即可。如果要编译单个项目。右键 - 仅用于项目 -仅重新生成。


    【在pocket pc 2003 上使用gtest】
    近期把一个cpp代码,在vs2008上从win32带控制台的,移植到智能设备pocket pc 2003上。但是有编译问题。最终通过以下方式解决。
    1 从google上的svn得到最新版本:先安装svn,然后右键-checkout-输入url:http://googletest.googlecode.com/svn/trunk/ - OK即可。
      包含gtest需要的库和头文件
    2 把WCE的预编译宏copy过来
    3 在msdn完整的说法是,建议在迁移evc的project时,
     Ignore Specific Library(忽略特定库) 加上 oldnames.lib
    AdditionalDependencies(附加依赖项)加上 commctrl.lib coredll.lib aygshell.lib secchk.lib ccrtrtti.lib
    4 编译后可以通过,然后就可以在自己的测试工程里面使用这个gtestd.lib了

     

xavier_007

xavier_007

目前从事gis行业导航相关测试; 熟悉语言c/cpp/vbs/lua/java 熟悉工具gtest/autoit/qtp/lr 良好英语和思维能力

数据统计

  • 访问量: 11394
  • 日志数: 18
  • 建立时间: 2008-11-26
  • 更新时间: 2012-11-21

RSS订阅

Open Toolbar