如何有效使用CPPUnit? [英] How to use CPPUnit effectively?

查看:73
本文介绍了如何有效使用CPPUnit?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何有效地使用CPPUnit?

当我想使用CPPUnit时,我总是把它弄得没用,浪费我的时间。

我认为这主要是

因为我不知道如何有效地使用CPPUnit。所以,如果有人

这里有一些经验,

请分享给我。

我也期待这些问题的答案:

1.我应该为我班级的每个成员函数编写测试代码吗?如果

没有,应该测试哪个函数?

2.除了检查参数和

返回值之外我还应该考虑什么?


谢谢。

How to use CPPUnit effectively?
When I want to use CPPUnit, I always fint it useless and waste my time.
I think that''s mainly
because I don''t know how to use CPPUnit effectively. So if somebody
here has some experience,
please share it to me.
And also I expect answers to these questions:
1. Should I write test codes for every member function of my class? If
not, which function should be tested?
2. What else should I consider apart from checking parameters and
return value?

Thanks.

推荐答案

Hooyoo写道:
Hooyoo wrote:

如何有效地使用CPPUnit?

当我想使用CPPUnit时,我总是把它弄得没用,浪费我的时间。

我认为'' s主要是因为我不知道如何有效地使用CPPUnit。所以,如果有人

这里有一些经验,

请分享给我。
How to use CPPUnit effectively?
When I want to use CPPUnit, I always fint it useless and waste my time.
I think that''s mainly
because I don''t know how to use CPPUnit effectively. So if somebody
here has some experience,
please share it to me.



像任何其他新软件一样,从编译和运行的最小例子

Like any other new piece of software, start with the smallest example
that compiles and runs, say a TestFixture with single test.


我还期待这些问题的答案:

1.我应该为我班级的每个成员函数编写测试代码吗?如果

没有,应该测试哪个功能?
And also I expect answers to these questions:
1. Should I write test codes for every member function of my class? If
not, which function should be tested?



首先编写测试,然后根据需要添加成员。

Write the tests first and the members will be added as you require them.


2.什么否则我应该考虑除了检查参数和

返回值?
2. What else should I consider apart from checking parameters and
return value?



副作用。


-

Ian Collins。

Side effects.

--
Ian Collins.


Hooyoo写道:
Hooyoo wrote:

如何有效使用CPPUnit?
How to use CPPUnit effectively?



使用UnitTest ++。它更精简,更易于使用:

http: //unittest-cpp.sourceforge.net/


CppUnit充满了你不需要的功能,他们经常进入
$ b你做的少数人的$ b方式。

Use UnitTest++. It''s much leaner and easier to use:

http://unittest-cpp.sourceforge.net/

CppUnit is stuffed with features you won''t need, and they often get in the
way of the few you do.


当我想使用CPPUnit时,我总是把它弄得没用,浪费我的时间。
When I want to use CPPUnit, I always fint it useless and waste my time.



你还要花很多时间调试吗?难道你不觉得_that有点

更无用和浪费?

Do you still spend a lot of time debugging? Don''t you feel _that''s_ a little
more useless and wasteful?


我认为这主要是

因为我不知道如何有效地使用CPPUnit。
I think that''s mainly
because I don''t know how to use CPPUnit effectively.



您应该为代码的每一行(或两行)编写测试。永远不要在没有测试失败的情况下编写新的代码。


如果测试意外失败,请使用Undo将代码恢复到最后一个

表示它通过的地方。这个简单的技巧几乎可以处理所有调试。

You should write tests for each new line (or two) of the code. Never write
new code without a failing test.

If a test fails unexpectedly, use Undo to revert the code back to the last
state where it passed. This simple trick takes care of nearly all debugging.


1.我应该为我班级的每个成员函数编写测试代码吗?如果

没有,应该测试哪个功能?
1. Should I write test codes for every member function of my class? If
not, which function should be tested?



要使函数存在,您需要进行测试。为了改变它的行为,

你需要另一个测试。等等。

To make the function exist, you need a test. To make its behavior change,
you need another test. And so on.


2.除了检查参数和

返回值之外我还应该考虑什么?
2. What else should I consider apart from checking parameters and
return value?



您编写的每个测试用例,首先运行它并查看它是否失败。测试应该因为正确的原因而失败。理论上,任何类型的代码都可以通过

测试,因此您应该编写足够的代码来传递。如果代码错误,

它应该在简单性方面犯错。


然后编写另一个测试来强制错误。这些测试一起,将b
约束该函数的内部结构。


结果就好像测试用例全部勾结以约束所有

函数'的内部线条,虽然每个测试用例都太简单了。


-

Phlip
http://www.greencheese.us/ZeekLand < - 不是博客!! !

Each test case you write, run it first and see if it fails. The test should
fail for the correct reason. Any kind of code could, in theory, pass the
test, so you should then write just enough code to pass. If the code errs,
it should err on the side of simplicity.

Then write another test to force out the error. These tests, together, will
constrain the innards of that function.

The result works as if the test cases all colluded to constrain all the
function''s internal lines, though each test case alone is too simple.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!




Phlip写道:

Phlip wrote:

Hooyoo写道:
Hooyoo wrote:

如何有效使用CPPUnit?
How to use CPPUnit effectively?



使用UnitTest ++。它更精简,更易于使用:

http: //unittest-cpp.sourceforge.net/



压缩源中的MS VC项目让我很恶心。

The MS VC project in the zipped source makes me disgusting.


CppUnit充满了你不需要的功能,并且它们经常以你所做的少数几种方式进入。
CppUnit is stuffed with features you won''t need, and they often get in the
way of the few you do.

当我想使用CPPUnit时,我总是把它弄得没用,浪费我的时间。
When I want to use CPPUnit, I always fint it useless and waste my time.



你还要花很多时间调试吗?难道你不觉得_that有点

更无用和浪费?


Do you still spend a lot of time debugging? Don''t you feel _that''s_ a little
more useless and wasteful?


我认为这主要是

因为我不知道如何有效地使用CPPUnit。
I think that''s mainly
because I don''t know how to use CPPUnit effectively.



您应该为代码的每一行(或两行)编写测试。永远不要在没有测试失败的情况下编写新的代码。


如果测试意外失败,请使用Undo将代码恢复到最后一个

表示它通过的地方。这个简单的技巧几乎可以处理所有调试。


You should write tests for each new line (or two) of the code. Never write
new code without a failing test.

If a test fails unexpectedly, use Undo to revert the code back to the last
state where it passed. This simple trick takes care of nearly all debugging.


1.我应该为我班级的每个成员函数编写测试代码吗?如果

没有,应该测试哪个功能?
1. Should I write test codes for every member function of my class? If
not, which function should be tested?



要使函数存在,您需要进行测试。为了改变它的行为,

你需要另一个测试。等等。


To make the function exist, you need a test. To make its behavior change,
you need another test. And so on.


2.除了检查参数和

返回值之外我还应该考虑什么?
2. What else should I consider apart from checking parameters and
return value?



您编写的每个测试用例,首先运行它并查看它是否失败。测试应该因为正确的原因而失败。理论上,任何类型的代码都可以通过

测试,因此您应该编写足够的代码来传递。如果代码错误,

它应该在简单性方面犯错。


然后编写另一个测试来强制错误。这些测试一起,将b
约束该函数的内部结构。


结果就好像测试用例全部勾结以约束所有

函数'的内部线条,虽然每个测试用例都太简单了。


-

Phlip
http://www.greencheese.us/ZeekLand < - 不是博客!! !


Each test case you write, run it first and see if it fails. The test should
fail for the correct reason. Any kind of code could, in theory, pass the
test, so you should then write just enough code to pass. If the code errs,
it should err on the side of simplicity.

Then write another test to force out the error. These tests, together, will
constrain the innards of that function.

The result works as if the test cases all colluded to constrain all the
function''s internal lines, though each test case alone is too simple.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!


这篇关于如何有效使用CPPUnit?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆