DEV Community

Discussion on: Where Should Tests Live?

Collapse
 
tyrw profile image
Tyler Warnock

As usual, it depends.

For our backend (API) code, I much prefer keeping the tests completely separate from the server code, as it feels like I'm building a machine to test my other machine. I don't like much, if any, overlap there as it encourages code reuse between tests and production code, which can be problematic if a bug gets introduced into the shared code. These tests also feel more "important" than the frontend tests because the backend shoulders more responsibility for our data integrity, whereas bugs on the frontend tend to affect display and/or website functionality.

For our frontend code, it's nice to keep the tests closer to the production code since we generally have a lot of smaller parts broken out at various levels of the file tree (vs backend, which tends to fall under models, utils, config, etc). I also find that our frontend tests tend to treat smaller pieces of code, particularly because integration tests on the frontend seem to be so slow to write and execute.

So net-net for us: we keep a lot of separation on the backend but tests live close to the code they test on the frontend.