DEV Community

Discussion on: Tips for testing web applications

Collapse
 
ozzythegiant profile image
Oziel Perez • Edited

The best way to "Mock a database" is to create a SQLite database on the fly inside your unit tests and test against that. That way whatever code you're using to fetch and post data can be tested against that, should you not want to hit your database directly. As for hitting the real database, this should be part of a larger "Integration Test", where you start all the way at the front end by making a web request and ensuring that your data is fetched/posted properly at the database.

Collapse
 
robsontenorio profile image
Robson Tenório

But just remember sometimes if you use an special DB function SQLite won’t be enough.

Collapse
 
thisdotmedia_staff profile image
This Dot Media

Great point Oziel