6 ms·
Mocking own code should be avoided if possible, but it does not apply to external resources like database, http responses etc.
by older 4y ago
Mocking own code should be avoided if possible, but it does not apply to external resources like database, http responses etc.
- simonw 4y agoI don't think it's ever a good idea to mock a database. Invest in a test framework that can performantly spin up a fresh database instance and throw it away at the end of the test run instead. Mocking outbound HTTP calls is worthwhile, but thankfully most testing frameworks I've used (at least in Python world) make that pretty easy.
- older 4y agoI mock database by using sqlite in-memory database. It is not 100% compatible with my production database but still god enough for most of my tests. This way I have fresh database for each unit test and the tests are still fast.