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