Hacker News new | ask | show | jobs
by hitchstory 516 days ago
If you're working with a big ball of mud, I find that the best approach is to immediately start doing TDD with hermetic end to end tests.

Hermetic = could run just fine on their own if run on a freshly installed OS that is cut off from the internet.

The first tests you build this way will be extraordinarily expensive (faking databases & http calls is fiddly), but they pay enormous dividends.

Once you have a large enough body of these and youve refactored some clean interfaces underneath, you can start writing future tests against those.

1 comments

I'm firmly in the camp that you shouldn't mock the DB and have a local instance for testing but for external resources that you can't reproduce locally I think that's fine.

Otherwise I agree with you.

By faking the DB I meant either running a local, prefilled fake DB server for every test or faking the interface to the DB.

Which one you should do depends on how complex your interactions with the DB are.

Some apps (e.g. CRUD) have half of their business logic encoded in DB queries in which case faking the calls is a bad idea.

Others only do, like, 2 simple queries. In this case there's no point running an actual database outside of a couple of E2E tests.

Yup then I'm with you