c++ boost.test与CppUnit

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

内容简介:任何人都可以告诉我两个框架之间的差异和使用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


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

查看所有标签

猜你喜欢:

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

Python for Everyone

Python for Everyone

Cay S. Horstmann、Rance D. Necaise / John Wiley & Sons / 2013-4-26 / GBP 181.99

Cay Horstmann's" Python for Everyone "provides readers with step-by-step guidance, a feature that is immensely helpful for building confidence and providing an outline for the task at hand. "Problem S......一起来看看 《Python for Everyone》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具