views:

517

answers:

3

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  A: 

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

Craig Stuntz
+2  A: 

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
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
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
I just don't agree with #2 item.
Gedean Dias
TDataSource 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 Pluimers
+2  A: 

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

mjustin