Originally posted by bob philbin:
One application I've written demands a great deal of database interaction, and I've not found any good way to use ATDD because of that. It seems like I'll have to write way too much code just populating tables for a given test and thus embedding new sources of error. Does your C6 (or other parts of your book) cover this? Do you have suggestions for db-intensive ATDD?
Thanks,<br /> <br />Paul Croarkin<br />SCEA 5, SCWCD, SCJP
Originally posted by bob philbin:
One application I've written demands a great deal of database interaction [...] It seems like I'll have to write way too much code just populating tables for a given test and thus embedding new sources of error. Does your C6 (or other parts of your book) cover this?
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Originally posted by Craig Bayley:
Being a service oriented architecture, with many provider systems we have no control over, it is easier for us to "mock" the database than to try and keep up with possible changes. Our automated test framework would catch changes as failing tests, but that smacks of false positives...
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Originally posted by Charles Hasegawa:
I think the question is what do you mean by database testing?
Interactions with the DAO's are one test - ie do my objects use my DAO's appropriately and handle errors or bad data the way I expect. In most of these cases, the correct answer is mock object. Mock object will let you define the behaviors (ie I expect x going in to return 5 rows of data that will be a-b-c-d-e, so just give me that - OR - if I call this with a bad value I should get an exception, do I handle that correctly).
The DAO interaction with the database is another set of tests. Do my DAO's save the data correctly? Do they retrieve data correctly for given inputs? Are my transactions handled properly when there are problems? For these tests, DBUnit is one of your better choices. You set the initial state of the database and the expected state of the database as XML files. The framework handles the loading of the data and will also handle verification. It is a bit tedious writing the XML if you are testing on large datasets, but it beats most of the alternatives...
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Originally posted by Charles Hasegawa:
I don't really understand the question...
The DAO is your last entry point between the raw data store (whether that is a DB or flat files or whatever), so how/why would you think to use mock objects to test the DAO?
Originally posted by Himanhsu Yadav:
Do I need not to unit test DAOs as I dont have any local DB.
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Originally posted by Lasse Koskela:
A unit test by definition does not touch an actual database. Instead, you unit test your DAOs in isolation from the database--usually against mock objects.
Originally posted by Charles Hasegawa:
I'd argue that isn't that case. Testing your DAOs with mocks to test that the results are handled correctly is one test. I'd argue that testing that the DAO is asking for the correct information is just as important.
- Is the SQL formed correctly (ie, did we incorrectly set any params)?
- Did I write the SQL correctly - select from the correct table, join correctly, ask for the correct column names, etc.
- Does my SQL update the database correctly - does my sql leave the DB in the state I believe it should be left?
[...]
Mocks have their place in helping to isolate parts of your code, but you can't say that your DAOs are well tested if you never check the datastore's state.
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Originally posted by Lasse Koskela:
Yes, but those aren't unit tests. They're integration tests.
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Originally posted by M Mistroni:
as i think we should NOT Use a method (create()) that is supposed to be tested by itself ...
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Originally posted by M Mistroni:
let's assume then that there's something wrong with your dao.create such as the population of the db fails.
then, for each and every testMethod method - where you should test the invocation of method Method - , you are actually calling 2 methods of your class - the create, and the methodMethod.
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2