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?
Unit-testing Delphi data modules
Asked Answered
After the last question about this, I wrote a blog post about how to do it.
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.
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
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
© 2022 - 2024 — McMap. All rights reserved.