Verifying data in database as part of automated testing
I have a general question around best practices and what is typically done in automated testing with Selenium (or others).
Lets say we had to test a registration process which has three pages:
- A registration page where the users provides their details (name, address etc.) and clicks submit
- A confirmation page which confirms that the registration is complete
- A failure page if the registration failed.
Normally, when automating the test, I have been coding that if the confirmation page is displayed then the test has passed.
My question is if the automated test also check the database to verify that the details were correctly saved before considering that the test has passed. How would you approach this?
Generally verifying using the Database is a bad idea. Makes your test very brittle and vulnerable to schema changes. Ideally, you'll want to use an API call to make that verification, even if you need to create one for testing.
If that is not an option, another option is to import the developer's data models they're using in their ORM so that you don't have to maintain the data mappings.