Unit-testing Delphi data modules

2020-05-28 19:23发布

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?

3条回答
小情绪 Triste *
2楼-- · 2020-05-28 19:58

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.

查看更多
小情绪 Triste *
4楼-- · 2020-05-28 20:17

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

查看更多
登录 后发表回答