Unit-testing Delphi data modules
Asked Answered
G

3

5

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?

Gill answered 23/1, 2009 at 13:50 Comment(0)
A
5

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

Associative answered 23/1, 2009 at 14:29 Comment(0)
D
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.

Doerr answered 23/1, 2009 at 19:57 Comment(4)
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;Cupped
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.Doerr
I just don't agree with #2 item.Miscreance
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)Matron
L
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

http://cc.embarcadero.com/Item/24136

alt text http://www.mikejustin.com/images/OpenCTF.gif

Lew answered 26/3, 2009 at 14:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.