9 ms·
Testing against a real database is an example of integration testing. Using mocks is for unit testing. Ideally, you want to do both. Unit testing entails isolat
by astine 2y ago
Testing against a real database is an example of integration testing. Using mocks is for unit testing. Ideally, you want to do both. Unit testing entails isolating particular components for testing which is important because it let's you be more precise in what exactly you're testing. Using mocks also makes it easier to run automated tests because it means you don't need to have a database or credentials handy during the build process.
Integration testing is also important because the closer you get to running things in a production environment, the more likely you are to detect issues. Some things just won't be apparent until you start running code in production or near production. The thing to understand though, is that you want to do both if you can, not either-or.
- nwatson 2y agoThen just use a database for unit testing as well.
- globular-toast 2y agoThen you get a slow test suite. It's important to have a fast test suite to be able to do proper test driven development (which I still believe is the most efficient and effective way to write software, in general). Unit tests should be near 100% coverage. That means a lot of tests.
- peterldowns 2y agoThat's not always true — database-backed tests can be extremely fast, see https://github.com/peterldowns/pgtestdb https://github.com/peterldowns/pgtestdb.
- bluGill 2y agodatabases can run hundreds of test in a ms. Sure without you could get to thousands in that ms - who cares.
- astine 2y agoBecause then you wouldn't be doing unit testing; you'd be doing integration testing. You'd also probably not be testing the database in a realistic configuration and thereby missing the whole point.