Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Let's say I have a `SomeEntity.get` function.

Basically it gets an array of id's and calls the database and fetches those entities.

~10 lines of Javascript code.

40 lines of SQL. Which also depends on the state of the database.

So what do I gain by mocking the database? Making sure those 10 lines of javascript work fine? In a vacuum? They are the 10 easy lines anyways which are covered by my E2E test.

What matters is the SQL and how it behaves in different states of the database.



And that’s why you test the DB with an integration test (and likely a functional test too).

For your unit test you’d just mock the dB call and make sure that function called the “db” and returned the faux data. That’s it.

No one said unit tests had to be complex or test the whole stack. Quite the opposite actually.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: