Re:c ++类设计:把调试目的实用程序类放在哪里? [英] Re: c++ class design: where to put debug purpose utility class?

查看:59
本文介绍了Re:c ++类设计:把调试目的实用程序类放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1230987za写道:


但我认为定义单位有一个微妙的区别。我不能

同意James Kanze更多关于单元测试*当*单位是一个类,

但该单位是一个函数怎么样?一个班级的'公共职能?

我正在将测试驱动开发TDD改编成我的日常编程。



Kanze是一位受过经典训练的单位测试员。在某些圈子中,单位是一个QA

概念 - 具体来说,如果测试失败,你只需要检查一个单元。


所以单位是明确划定并且可以进行检查的东西。这应该映射到C ++类 - 特别是由于

重叠需求。 C ++类_should_是明确

分隔并可供检查的东西。但有时,根据需要,

单位是一个翻译单元,或一个标题,或一个特殊的包含文件,或一个

全局常量。

在TDD下,如果测试在开发过程中失败,你只需要检查(或

还原)最近的编辑。因此,开发人员测试和单元测试具有重叠的能力和动机。许多TDD测试还允许你将
隔离故障发送到一个小单元。


请耐心等待,我正在做 - 它 - 之前学习 - 它。我设计了我的

类接口,没有实现API函数,我开始设计我的测试类来测试每个API函数。正是在这一点上

我的问题即将来临。



这不是真正的TDD。您从测试开始,并将每个测试用例写入

说明目标类的一个方面。只有在你接受测试后才能告诉你要在课堂上添加什么,然后再添加它。所以想象一下,如果你的

方法.activate()还不存在:


test_case

Foo aFoo

result = aFoo.activate

断言结果== 42

第一次运行时,如果激活尚不存在,则添加它。

然后再次运行它,然后发现激活没有返回值。

第三次,你运行它并发现返回值是错误的。只有在

之后才对这种情况进行严格审查 - 确定测试失败

正确的原因 - 你是否将实际逻辑放在方法中。


你以小周期重复这种激进的测试(并在每次微小的抽搐之间整合

)来增加界面。


我在2组,C ++和Object上发布了我的问题,有趣的是

足够,我看到C ++组中的人们一致认为单位类是

而Object对象为我提供了更多不同的观点。



" Class"对于单位是好的。但有时候这个单元是一个独立的一组

开关,在微观测试垫之间,在一个大的集成

电路的深处。


-

Phlip
http://assert2.rubyforge .org /

解决方案

6月29日下午4:10,Phlip < phlip2 ... @ gmail.comwrote:


1230987za写道:


但我认为那里定义单位是一个微妙的差异。我的b $ b不能同意James Kanze更多关于单元测试*当*

单位是一个类时,但该单位是一个函数怎么样?

级''公共职能?


我正在将测试驱动开发TDD改编成我的每日

编程。


Kanze是一位受过经典训练的单位测试员。在某些圈子中

" unit"是一个质量保证概念 - 具体来说,如果测试失败,你只需要检查一个单元。



你的意思是我在标准接受的含义中使用了一个词。

(单元测试是开发的必要部分许多,

多年了。)


所以单位是明确划定的东西,并且可以通过检查获得



这或多或少是单位的定义,是的。在实践中,

单位是单位---它们或多或少是

层次结构开发中的最低级别。


应映射到C ++类 -



为什么?那是我第一次听到这个消息。 (有很多

的情况,它们映射到C ++类。)


特别是由于需求重叠。 C ++类

_should_是明确分隔和可访问的东西

to inspection。然而,有时,必要时,单位是指单位。是一个

翻译单元,或标题,或一个特殊的包含文件,或

一个全局常量。



至少,单位是指永远不会少于翻译单位,

因为现有技术不允许你分解

更精细。 (当然,翻译单元通常不到一个完整的类。)


在TDD下,如果测试在开发过程中失败,你只需要

来检查(或恢复)最近的编辑。



对不起,但那是胡说八道。无论设计

哲学如何,如果你有一半体面的单元测试,那么错误很可能是由于最多的b / b
最近编辑。而且无论设计理念如何,总有一点点机会,即最近的变化中的某些东西很可能会触发一个之前已有的错误。 (这是一个未定义行为含义的
- 并且TDD不会从语言中移除

未定义的行为。)
< blockquote class =post_quotes>
因此,开发人员测试和单元测试具有重叠的能力

和动机。许多TDD测试还允许您将
故障隔离到一个小单元。



所有单元测试都允许您或多或少地将故障隔离到

小单元。然而,没有一个是完美的。


请耐心等待我,我在做它之前的学习它。我设计了我的类接口,没有实现API

函数,我开始设计我的测试类来测试每个

API函数。正是在这一点上我的问题出现了。


那不是真正的TDD。您从测试开始,并编写每个

测试用例来说明目标类的一个方面。



当然,这是不正确的,因为直到你有至少
,才知道这个课是什么你不能写

测试。首先确定要做什么类(在大多数情况下,这意味着一些高级设计)。只要输入代码,无论是测试还是其他任何内容,你都不会开始




(我觉得很难想象在这个时代,

人们仍然建议我们在我们思考之前编码。并且

建议它作为银弹,不能少。)


-

James Kanze(GABI软件)电子邮件:ja ********* @ gmail.com

Conseils en informatique orientéeobjet/

Beratung in objektorientierter Datenverarbeitung

9placeSémard,78210 St.-Cyr-l''coco,France,+ 33(0)1 30 23 00 34


James Kanze写道:


6月29日下午4:10,Phlip < phlip2 ... @ gmail.comwrote:


> Kanze是一位受过经典训练的单位测试员。在某些圈子中单位是一个QA概念 - 具体来说,如果测试失败,您只需要检查一个单元。


[...]


>这不是真正的TDD。您从测试开始,编写每个
测试用例来说明目标类的一个方面。



当然,这是不正确的,因为在你至少获得
之前,我想知道这是什么类你不能写

测试。首先确定要做什么类(在大多数情况下,这意味着一些高级设计)。只要输入代码,无论是测试还是其他任何内容,你都不会开始




(我觉得很难想象在这个时代,

人们仍然建议我们在我们思考之前编码。并且

建议它作为银弹,不低于。)



实际上有些人这样做。 :-)


但是这取决于你的宗教信仰程度,以及你想要的严格程度

来遵循教条。


如果你只想说你做TDD,你可以用单个测试用例开始




断言(假);


这肯定会失败,然后您可以自由开始编码

设计。只记得经常编译,并确保测试

仍然失败!


最终,你将发现故障不在您的代码中,

但在测试用例中。然后是时候改进了。测试。如果你只是不打电话给他们进行单元测试,而是用例,你就完成了。


即时TDD(tm)。


Bo Persson


Bo Persson写道:


James Kanze写道:


>当然,这不是真的,因为直到你至少考试。


实际上有些人这样做。 :-)


然而,这取决于你的宗教信仰,以及你想要多严格地遵循这些教条。




您希望从实施设计强制到

获得多少好处。当然,它可能会遵循您的初步草图。但它可能没有。


有些人在严格限制下设计不够严谨...


-

Phlip


1230987za wrote:

But I think there is a subtle difference to define "unit". I can not
agree with James Kanze more on unit test *when* the unit is a class,
but how about the unit is a function? A class'' public function?

I am adapting Test Driven Development, TDD, into my daily programming.

Kanze is a classically-trained "unit tester". In some circles "unit" is a QA
concept - specifically, if a test fails, you only need to inspect one unit.

So "units" are "things which are clearly delimited and accessible to
inspection". That should map onto C++ classes - specifically due to
overlapping requirements. C++ classes _should_ be "things which are clearly
delimited and accessible to inspection". Yet sometimes, by necessity, the
"unit" is a translation unit, or a header, or a peculiar include file, or a
global constant.

Under TDD, if a test fails during development, you only need to inspect (or
revert) the most recent edit. So Developer Tests and Unit Tests have
overlapping abilities and motivations. Many TDD tests will also allow you to
isolate faults to a small unit.

Please bear with me, I am doing-it-before-learning-it. I designed my
class interface, without implementing the API functions, I started
designing my test class to test each API function. It is at this point
my question coming up.

That''s not really TDD. You start at the test, and write each test case to
illustrate one aspect of your target class. Only after you get the test to
tell you what to add to the class, next, do you add it. So imagine if your
method .activate() did not exist yet:

test_case
Foo aFoo
result = aFoo.activate
assert result == 42

The first time you run that, if activate does not exist yet, you add it.
Then you run it again, and "discover" that activate has no return value. The
third time, you run it and discover the return value is wrong. Only after
this rigorous review of the circumstances - to determine the test is failing
for the correct reason - do you put the actual logic inside the method.

You repeat this aggressive testing, in small cycles (and integrating between
each tiny twitch) to grow an interface.

I posted my question on 2 groups, C++ and Object, interestingly
enough, I see folks in C++ group unanimously think "unit" is class
while Object folks provide me more diverse viewpoints.

"Class" is good for "Unit". But sometimes the Unit is one isolated group of
switches, between microscopic test pads, deep inside a big integrated
circuit.

--
Phlip
http://assert2.rubyforge.org/

解决方案

On Jun 29, 4:10 pm, "Phlip" <phlip2...@gmail.comwrote:

1230987za wrote:

But I think there is a subtle difference to define "unit". I
can not agree with James Kanze more on unit test *when* the
unit is a class, but how about the unit is a function? A
class'' public function?

I am adapting Test Driven Development, TDD, into my daily
programming.

Kanze is a classically-trained "unit tester". In some circles
"unit" is a QA concept - specifically, if a test fails, you
only need to inspect one unit.

You mean I''m using a word in its standardly accepted meaning.
(Unit tests have been a required part of development for many,
many years now.)

So "units" are "things which are clearly delimited and
accessible to inspection".

That''s more or less a definition of "unit", yes. In practice,
units are units---they''re more or less the lowest level in a
hierarchial development.

That should map onto C++ classes -

Why? That''s the first time I''ve heard that. (There are a lot
of cases where they do map onto C++ classes.)

specifically due to overlapping requirements. C++ classes
_should_ be "things which are clearly delimited and accessible
to inspection". Yet sometimes, by necessity, the "unit" is a
translation unit, or a header, or a peculiar include file, or
a global constant.

As a minimum, a "unit" is never less than a translation unit,
since current technology doesn''t allow you to break things down
any finer. (Of course, a translation unit is often less than a
complete class.)

Under TDD, if a test fails during development, you only need
to inspect (or revert) the most recent edit.

I''m sorry, but that''s bullshit. Regardless of the design
philosophy, if you have halfway decent unit tests, there is a
high probability that the error is somehow due to the most
recent edit. And regardless of the design philosophy, there''s
always a small chance that something in the recent change has
triggered an error which was already there before. (That''s one
of the meanings of undefined behavior---and TDD doesn''t remove
undefined behavior from the language.)

So Developer Tests and Unit Tests have overlapping abilities
and motivations. Many TDD tests will also allow you to isolate
faults to a small unit.

All unit tests allow you to more or less isolate faults to a
small unit. None are perfect, however.

Please bear with me, I am doing-it-before-learning-it. I
designed my class interface, without implementing the API
functions, I started designing my test class to test each
API function. It is at this point my question coming up.

That''s not really TDD. You start at the test, and write each
test case to illustrate one aspect of your target class.

Which, of course, isn''t true, because until you have at least
some idea as to what the class is to do, you can''t write the
tests. You start by determining what the class is to do (in
most cases, that means some high level design). You don''t start
by just typing in code, whether it is a test or anything else.

(I find it very hard to conceive that in this day and age,
people are still suggesting that we code before we think. And
proposing it as a silver bullet, no less.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l''école, France, +33 (0)1 30 23 00 34


James Kanze wrote:

On Jun 29, 4:10 pm, "Phlip" <phlip2...@gmail.comwrote:

>Kanze is a classically-trained "unit tester". In some circles
"unit" is a QA concept - specifically, if a test fails, you
only need to inspect one unit.


[...]

>That''s not really TDD. You start at the test, and write each
test case to illustrate one aspect of your target class.


Which, of course, isn''t true, because until you have at least
some idea as to what the class is to do, you can''t write the
tests. You start by determining what the class is to do (in
most cases, that means some high level design). You don''t start
by just typing in code, whether it is a test or anything else.

(I find it very hard to conceive that in this day and age,
people are still suggesting that we code before we think. And
proposing it as a silver bullet, no less.)

Some people do, actually. :-)

However it depends on how religious you are, and how strictly you want
to follow the dogmas.

If you just want to be able to say that you do TDD, you can start out
with the single test case

assert(false);

This will surely fail, and you are then free to start coding your
design. Just remember to compiler often, and make sure that the test
still fails!

Eventually, you will "discover" that the fault is not in your code,
but in the test case. Then it is time to "refine" the tests. If you
just don''t call them unit tests, but use cases, you''re done.

Instant TDD(tm).

Bo Persson


Bo Persson wrote:

James Kanze wrote:

>Which, of course, isn''t true, because until you have at least
some idea as to what the class is to do, you can''t write the
tests.

Some people do, actually. :-)

However it depends on how religious you are, and how strictly you want
to follow the dogmas.

And how much benefit you''d like to get from forcing the implementation design to
emerge. Naturally, it might follow your preliminary sketches. But it might not.

Some people are not rigorous enough to design under such tight constraints...

--
Phlip


这篇关于Re:c ++类设计:把调试目的实用程序类放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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