Delphi 数据模块的单元测试

发布于 2024-07-12 05:30:02 字数 81 浏览 6 评论 0原文

如果所有业务逻辑都存在于数据模块(TSQLDataSets 和 TDataSetProviders)中,您将如何重构代码以使应用程序更适合单元测试?

If all the business logic is present in a datamodule (TSQLDataSets and TDataSetProviders) how would you refactor the code to make the application more appropiate for unit testing?

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

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

发布评论

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

评论(3

战皆罪 2024-07-19 05:30:02

一些基本提示:

  • 您的 DataModule 永远不应该引用表单或任何其他 UI 组件
  • 将 TDataSource 放在表单上,​​而不是放在您的 DataModule 中。
  • 确保没有任何确认提示和需要用户输入 DataModules 代码的操作。
  • 您不应该使用任何全局变量。

希望这可以帮助。

Some basic tips:

  • Your DataModules should never have any references to forms or any other UI components
  • Put the TDataSources on forms and not in your DataModules.
  • Make sure there isn't any prompts for confirmation and operations that requires user input on DataModules code.
  • You should not use any global vars.

Hope this helps.

荒岛晴空 2024-07-19 05:30:02

对于 DUnit 测试的自动构建,您可以使用 OpenCTF,它能够在测试运行时自动查找所有组件并创建测试用例。 示例测试包括一些基本的数据访问层测试。

http://sourceforge.net/projects/openctf/

http://cc.embarcadero.com/Item/24136

替代文本 http://www.mikejustin.com/images/OpenCTF.gif

For automated construction of tests for DUnit, you could use OpenCTF, which is able to find all components and create test cases automatically at test run time. The example tests include some basic data access layer tests.

http://sourceforge.net/projects/openctf/

and

http://cc.embarcadero.com/Item/24136

alt text http://www.mikejustin.com/images/OpenCTF.gif

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