c++ boost.test与CppUnit

栏目: C++ · 发布时间: 7年前

内容简介:任何人都可以告诉我两个框架之间的差异和使用boost.test的好处(如果有的话)?http://stackoverflow.com/questions/3100322/boost-test-vs-cppunit

任何人都可以告诉我两个框架之间的差异和使用boost.test的好处(如果有的话)?

自己一个忙,直奔 Google Test

,这使得CppUnit和boost :: unit_test看起来很笨重又重复.

例如,说你有一个简单的灯具:

class MyFixture : public ::testing::Test
{
  protected:
  int foo;

  virtual void SetUp() { foo = 0; }
};

要添加一个测试到你的夹具,写下来!

TEST_F(MyFixture, FooStartsAtZero) {
  EXPECT_EQ(0, foo);
}

这就是你需要的.请注意,缺乏明确的测试声明或单独的议程重复您的所有测试名称.

将其编译成

$g++ -o utest utest.cpp -lgtest -lgtest_main

并运行你的测试得到

Running main() from gtest_main.cc
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from MyFixture
[ RUN      ] MyFixture.FooStartsAtZero
[       OK ] MyFixture.FooStartsAtZero (0 ms)
[----------] 1 test from MyFixture (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[  PASSED  ] 1 test.

(自己运行,看看通过测试的漂亮绿色文字!)

这仅仅是个开始.看看 Google Test primeradvanced guide 看看还有什么可能的.

http://stackoverflow.com/questions/3100322/boost-test-vs-cppunit


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

How to Solve It

How to Solve It

Zbigniew Michalewicz、David B. Fogel / Springer / 2004-03-01 / USD 59.95

This book is the only source that provides comprehensive, current, and detailed information on problem solving using modern heuristics. It covers classic methods of optimization, including dynamic pro......一起来看看 《How to Solve It》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具