使用 Bold for Delphi 框架进行编码时提高可测试性

发布于 2024-12-09 12:42:21 字数 1292 浏览 0 评论 0原文

背景 我在一个由 7 名开发人员和 2 名测试人员组成的团队中工作,负责物流系统。 我们使用 Delphi 2007 和模型驱动开发,以 Bold for Delphi 作为框架。 该系统现已投入生产约 7 年,拥有约 170 万行代码。 我们在 4-5 周后发布到生产环境,几乎每次发布后我们都必须针对我们没有发现的错误进行一些补丁。这对我们和客户来说当然都是令人恼火的。

当前测试 解决方案当然是更加自动化的测试。目前我们有手动测试。 Testdbgenerator 从空数据库开始,并从建模方法添加数据。我们还有 Testcomplete,它运行一些非常基本的脚本来测试 GUI。由于缺乏时间,我们无法添加更多测试,但脚本对应用程序中的更改也很敏感。几年前,我确实尝试过使用 DUnit 进行单元测试,但几天后我就放弃了。这些单位之间的联系太强。

单元测试先决条件 我想我知道单元测试的一些先决条件:

  • 编写只做一件事的小方法,但要把它做好。
  • 不要重复自己。
  • 首先编写失败的测试,然后编写代码以使测试通过。
  • 各单元之间的连接应松动。他们应该对彼此了解不多。
  • 使用依赖注入。

使用的框架 我们可能会升级到Delphi XE2,主要是因为64位编译器。 我稍微研究了一下 Spring 但这需要从 D2007 进行更新并且现在这种情况不会发生。也许明年。

问题 大多数代码仍未自动测试。那么提高旧代码的可测试性的最佳途径是什么?或者也许最好开始只为新方法编写测试? 我不确定增加自动测试的最佳方法是什么,欢迎对此发表评论。我们可以现在使用D2007 + DUnit,然后轻松更改为Delphi XE2 + Spring吗?

编辑:关于手动测试的当前测试方法只是“重击并尝试打破它”,如 克里斯称之为。

Background
I work in a team of 7 developers and 2 testers that work on a logistics system.
We use Delphi 2007 and modeldriven development with Bold for Delphi as framework.
The system has been in production about 7 years now and has about 1,7 millions lines of code.
We release to production after 4-5 weeks and after almost every release we have to do some patches for bugs we don’t found. This is of course irritating both for us and the customers.

Current testing
The solution is of course more automatic testing. Currently we have manual testing. A Testdbgenerator that starts with an empty database and add data from the modelled methods. We also have Testcomplete that runs some very basic scripts for testing the GUI. Lack of time stop us from add more tests, but scripts is also sensitive for changes in the application. For some years ago I really tried unit testing with DUnit, but I gave up after some days. The units have too strong connections.

Unit testing preconditions
I think I know some preconditions for unit testing:

  • Write small methods that do one thing, but do it well.
  • Don’t repeat yourself.
  • First write the test that fails, then write the code so the test pass.
  • The connections between units shold be loose. They should not know much about each other.
  • Use dependency injection.

Framework to use
We may upgrade to Delphi XE2, mainly because of the 64-bit compiler.
I have looked at Spring a bit but this require an update from D2007 and that will not happen now. Maybe next year.

The question
Most code is still not tested automatically. So what is the best path to go for increasing testability of old code ? Or maybe it is best to start writing tests for new methods only ?
I’m not sure what is the best way to increase automatic testing and comments about it is welcome. Can we use D2007 + DUnit now and then easily change to Delphi XE2 + Spring later ?

EDIT: About current test methodology for manual testing is just "pound on it and try to break it" as Chris call it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

苍暮颜 2024-12-16 12:42:21

您想要 Michael Feathers 所著的书,有效地使用旧代码< /a>.它展示了如何向未考虑到可测试性而编写的代码引入(单元)测试。

有些章节的命名是开发人员可能会为为什么测试旧代码很困难而给出的借口,并且它们包含案例研究和解决每个问题的建议方法:

  • 我没有太多时间,我必须更改它,
  • 我不能在测试工具中运行这个方法
  • 这个类太大了,我不希望它变得更大,
  • 我需要更改一个怪物方法,但我无法为其编写测试。

它还涵盖了许多打破依赖关系的技术;有些对您来说可能是新的,有些您可能已经知道但只是还没有想到使用。

You want the book by Michael Feathers, Working Effectively with Legacy Code. It shows how to introduce (unit) tests to code that wasn't written with testability in mind.

Some of the chapters are named for excuses a developer might give for why testing old code is hard, and they contain case studies and suggested ways to address each problem:

  • I don't have much time and I have to change it
  • I can't run this method in a test harness
  • This class is too big and I don't want it to get any bigger
  • I need to change a monster method and I can't write tests for it.

It also covers many techniques for breaking dependencies; some might be new to you, and some you might already know but just haven't thought to use yet.

执手闯天涯 2024-12-16 12:42:21

自动化单元测试的要求正是这样:

  1. 使用单元测试框架(例如DUnit)。
  2. 使用某种模拟框架。

第 2 项是最难的一项。

DRY,小方法,从测试开始,DI都是糖。首先您需要开始单元测试。边做边添加 DRY 等。减少耦合有助于使内容更容易进行单元测试,但如果不进行巨大的重构工作,您将永远无法减少现有代码库中的耦合。

考虑为新的内容和版本中更改的内容编写测试。随着时间的推移,您将获得合理的单元测试基础。新的和变化的东西也可以被重构(或写得很好)。

另外,请考虑一个自动构建过程,该过程运行单元测试并在构建中断时发送电子邮件。

这仅涵盖单元测试。对于 QA 测试人员,您将需要一个工具(它们存在,但我想不出任何工具)来允许他们运行自动化测试(不是单元测试)。

The requirements for automated unit testing are exactly this:

  1. use an unit testing framework (for example, DUnit).
  2. use some kind of mocking framework.

Item 2 is the tough one.

DRY, small methods, start with a test, and DI are all sugar. First you need to start unit testing. Add DRY, etc. as you go along. Reduced coupling helps to make stuff more easily unit tested, but without a giant refactoring effort, you will never reduce coupling in your existing code base.

Consider writing tests for stuff that is new and stuff that is changed in the release. Over time you will get a reasonable base of unit tests. New and changes stuff can also be refactored (or written nicely).

Also, consider an automated build process that runs unit tests and sends email when the build breaks.

This only covers unit testing. For QA testers, you will need a tool (they exist, but I can't think of any) that allows them to run automated tests (which are not unit tests).

夏夜暖风 2024-12-16 12:42:21

在我看来,你的测试团队太小了。我曾经工作过的团队中,质量检查部门的数量超过了开发人员的数量。考虑在适合较小周期的可管理块(功能、修复)的“冲刺”中工作。 “敏捷”会鼓励两周的冲刺,但这可能太紧了。不管怎样,这会让 QA 持续忙碌,在发布窗口之前工作得更远。现在,我怀疑他们是闲置的,直到你给他们大量的代码,然后他们就会被淹没。随着发布周期的缩短,您可以让更多的测试人员忙碌起来。

另外,您没有过多谈论他们的测试方法。他们是否有运行的标准脚本,根据预期的外观和行为来验证外观和行为?或者他们只是“猛击它并试图打破它”?

IMO,Dunit 测试很难因为数据库、通信等大量依赖项而进行。但它是可行的。我创建了自动运行数据库设置脚本的 DUnit 类(查找与正在测试的类同名的 .sql 文件,运行 sql,然后继续测试),并且非常有效。对于 SOAP 通信,我运行了一个 SoapUI 模拟服务,该服务返回预设结果,因此我可以测试我的通信。
这确实需要工作,但这是值得的。

Your testing team is too small, IMO. I've worked in teams where the QA dept outnumbers the Developers. Consider working in "sprints" of manageable chunks (features, fixes) that fit in smaller cycles. "Agile" would encourage 2-week sprints, but that may be too tight. Anyway, it would keep the QA constantly busy, working farther ahead of the release window. Right now, I suspect that they are idle until you give them a huge amount of code, then they're swamped. With shorter release cycles, you could keep more testers busy.

Also, you didn't say much about their testing methodology. Do they have standard scripts that they run, where they verify appearance and behavior against expected appearance and behavior? Or do they just "pound on it and try to break it"?

IMO, Dunit testing is hard to do with lots of dependencies like databases, communication, etc.. But it's do-able. I've created DUnit classes that automatically run database setup scripts (look for a .sql file with the same name as the class being tested, run the sql, then the test proceeds), and it's been very effective. For SOAP communications, I have a SoapUI mockservice running that returns canned results, so I can test my communications.
It does take work, but it's worth it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文