DEV Community

Discussion on: Where Should Tests Live?

Collapse
 
grahamcox82 profile image
Graham Cox

In all my Java projects, tests live in a separate tree - src/main vs src/test. In my node projects, tests live in separate files next to the file being tested.

In the Java case, it's trivial to have extra test code that is there to support your tests. It's also easy to see what is test code and what is production code.

In the Node case, it originally started because of the require syntax - when I did it with separate trees I had hellish require paths. However, it's kinda nice having them so close together. You can see what is and isn't tested trivially, and flip between them really easily.

I like the idea of having them in the same file, but haven't tried it out properly yet.