boost.test主场迎战的CppUnit [英] boost.test vs. CppUnit
问题描述
我一直在使用CppUnit的相当长一段时间,现在(和我喜欢它)。由于我们使用Boost库越来越多的地方我有boost.test短期看,现在我想知道我是否应该切换到boost.test在一个新的项目或没有。
I've been using CppUnit for quite a while now (and am happy with it). As we are using more and more parts of the boost library I had a short look on boost.test and I'm wondering now if I should switch to boost.test in a new project or not.
可以在这里谁能告诉我关于这两个框架和效益之间的差异(如果有的话),使用boost.test的?
Can anyone here tell me about the differences between the two frameworks and the benefits (if there are any) of using boost.test?
推荐答案
请你帮个忙,并直接进入谷歌测试,这使得CppUnit的和的boost :: unit_test
看起来笨重,重复性的。
Do yourself a favor and go straight to Google Test, which makes CppUnit and boost::unit_test
look clunky and repetitive.
举例来说,假设你有一个简单的夹具:
For example, say you have a simple fixture:
class MyFixture : public ::testing::Test
{
protected:
int foo;
virtual void SetUp() { foo = 0; }
};
要测试添加到您的夹具,写出来!
To add a test to your fixture, write it!
TEST_F(MyFixture, FooStartsAtZero) {
EXPECT_EQ(0, foo);
}
这就是你需要的。注意,缺少明确的测试套件声明或重复所有的测试的名字一个单独的议程。
That's all you need. Notice the lack of explicit testsuite declarations or a separate agenda that repeats all your tests' names.
编译它作为
$ 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.
(运行它自己看到测试通过漂亮的绿色文本!)
(Run it yourself to see the nice green text for passing tests!)
这仅仅是个开始。看看在谷歌测试底漆和的高级指南来看看还有什么是可能的。
This is only the beginning. Take a look at the Google Test primer and the advanced guide to see what else is possible.
这篇关于boost.test主场迎战的CppUnit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!