如何开始对新旧代码进行单元测试?

发布于 2024-07-28 02:09:42 字数 358 浏览 1 评论 0原文

我承认我几乎没有单元测试的经验。 我不久前尝试过 DUnit,但放弃了,因为我的应用程序中的类之间存在太多依赖关系。 这是一个相当大的(大约 150 万行源代码)Delphi 应用程序,我们是一个维护它的团队。

目前的测试是由一个在发布之前使用它并报告错误的人完成的。 我还在 TestComplete 6 中设置了一些 GUI 测试,但由于应用程序的更改,它经常失败。

Bold for Delphi 用作数据库的持久性框架。 我们都同意单元测试是必经之路,我们计划用 ECO 作为持久性框架在 DotNet 中编写一个新应用程序。

我只是不知道从哪里开始单元测试...... 有什么好的书籍、网址、最佳实践等吗?

I admit that I have almost none experience of unittesting. I did a try with DUnit a while ago but gave up because there was so many dependencies between classes in my application.
It is a rather big (about 1.5 million source lines) Delphi application and we are a team that maintain it.

The testing for now is done by one person that use it before release and report bugs. I have also set up some GUI-tests in TestComplete 6, but it often fails because of changes in the application.

Bold for Delphi is used as persistance framework against the database.
We all agree that unittesting is the way to go and we plan to write a new application in DotNet with ECO as persistance framework.

I just don't know where to start with unittesting...
Any good books, URL, best practice etc ?

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

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

发布评论

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

评论(1

萌酱 2024-08-04 02:16:27

嗯,单元测试的挑战不是测试本身,而是编写可测试的代码。 如果编写代码没有考虑测试,那么您可能会遇到很大的困难。

无论如何,如果你可以重构,就进行重构以使其可测试。 尽可能不要将对象创建与逻辑混合在一起(我不知道delphi,但可能有一些依赖注入框架可以帮助实现这一点)。

此博客有很多关于测试的深入见解。 检查这个例如文章(我的第一个建议就是基于它)。

至于建议,请尝试首先测试代码的叶节点,即那些不依赖于其他类的类。 它们应该更容易测试,因为它们不需要模拟。

Well, the challenge in unit testing is not the testing itself, but in writing testable code. If the code was written not thinking about testing, then you'll probably have a really hard time.

Anyway, if you can refactor, do refactor to make it testable. Don't mix object creation with logic whenever possible (I don't know delphi, but there might be some dependency injection framework to help in this).

This blog has lots of good insight about testing. Check this article for instance (my first suggestion was based on it).

As for a suggestion, try testing the leaf nodes of your code first, those classes that don't depend on others. They should be easier to test, as they don't require mocks.

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