4 ms·
When you're developing, aren't you running a db server with a dev database for that? Just add another separate test db and use that for tests where appropriate.
by grey-area 7y ago
When you're developing, aren't you running a db server with a dev database for that? Just add another separate test db and use that for tests where appropriate.
Also, most unit tests don't need a db, it's more useful for integration tests.
- pc86 7y agoIf you're using a Repository pattern or similar you'll have a lot of unit tests where a database or db provider is an injected dependency.
- amw-zero 7y agoHitting a database in tests is an order of magnitude slower and also involves worrying about a lot more code, i.e. the database engine. You may or may not want to take on that burden.
- grey-area 7y agoI use the db for some tests, it's totally fine, because it's limited to those tests which actually need db access (most don't). It's also closer to the actual application behaviour than mocks and doesn't need to be maintained.