Unit-testing Delphi data modules

2020-05-28 19:47发布

问题:

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?

回答1:

After the last question about this, I wrote a blog post about how to do it.



回答2:

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.



回答3:

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