如何启动单元测试旧的和新的代码? [英] How to start unit-test old and new code?

查看:130
本文介绍了如何启动单元测试旧的和新的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



Delphi的粗体用作数据库的持久性框架。
我们都同意,单元测试是要走的路,我们打算在DotNet中使用ECO作为持久性框架编写一个新的应用程序。



我只是不知道从哪里开始单元测试...
任何好书,URL,最佳实践等?

解决方案

单元测试中的挑战不是测试本身,而是在编写可测试代码中。如果代码写成考虑测试,那么你可能会很难。



无论如何,如果可以重构,请重构使其成为可测试。不要将对象创建与逻辑混合(我不知道delphi,但是可能有一些依赖注入框架来帮助这个)。



此博客对测试有很多好的洞察力。检查这个文章(我的第一个建议是基于它)。



对于一个建议,首先尝试测试你的代码的叶节点,那些类不依赖别人。他们应该更容易测试,因为他们不需要嘲笑。


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 ?

解决方案

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.

这篇关于如何启动单元测试旧的和新的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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