Timeline for is it okay to mock a database when writing unit test?
Current License: CC BY-SA 4.0
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Sep 26, 2024 at 19:02 | comment | added | DaveG | @Steve It really depends on the application. The last system I worked on had a relatively simple structure and it was quicker and easier to create and populate a bit of test data than to keep mocks up to date. | |
| Sep 25, 2024 at 22:36 | comment | added | Steve | Agreed, but unless you're testing something in the database layer specifically (i.e. the part under test is that part of the database layer which would otherwise be a mock when testing non-database-layer parts), or testing a client-side part that is somehow tightly coupled to the database and can't easily be isolated from the database layer using a mock, then there's a considerable overhead to setting-up and resetting a real database engine when such setting-and-resetting would be only incidental to the purpose of performing a unit test of a non-database part. | |
| Sep 25, 2024 at 17:49 | comment | added | JacquesB | @Steve This depends on the kind of application. For a data-driven applications a significant part of complexity might be in queries and database operations. | |
| Sep 25, 2024 at 7:37 | comment | added | Steve | That's a lot of interpolation of things Khorikov forgot to mention! Also, with database applications, controlling how they share data between clients and across sessions, and whether they do it correctly, is the main design challenge. It's arguably of very limited benefit to involve the "real" database rather than a mock, and all the complexity of that involvement and the scripting of the setup and reset, if you're not testing the sharing or evolutionary aspects. | |
| Sep 25, 2024 at 6:37 | history | edited | JacquesB | CC BY-SA 4.0 | added 313 characters in body |
| Sep 25, 2024 at 6:14 | history | edited | JacquesB | CC BY-SA 4.0 | added 258 characters in body |
| Sep 25, 2024 at 6:07 | history | answered | JacquesB | CC BY-SA 4.0 |