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?
Asked
Active
Viewed 1,568 times
3 Answers
5
After the last question about this, I wrote a blog post about how to do it.

Community
- 1
- 1

Craig Stuntz
- 125,891
- 12
- 252
- 273
3
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.

Erick Sasse
- 2,779
- 3
- 24
- 30
-
Hm, if I don't put any datasources into my data module, how do I connect several tables/queries, eg.: datasource2.dataset=table2; table1.datasource = datasource2; – dummzeuch Mar 26 '09 at 15:10
-
I don't use this feature, but I guess in this case you have to put your datasource in DM, but just to connect datasets. See if you can use another Datasource to connect your dataset to visual components. – Erick Sasse Mar 27 '09 at 11:48
-
I just don't agree with #2 item. – Gedean Dias Mar 14 '10 at 16:40
-
5TDataSource can have 2 purposes: binding of UI Controls (then it should go on the form or frame), binding of master-detail relations (then it should go on the datamodule) – Jeroen Wiert Pluimers Mar 16 '10 at 19:09
2
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

mjn
- 36,362
- 28
- 176
- 378