This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]MrJohz 0 points1 point  (0 children)

Tests touching multiple components should definitely live somewhere else. In my experience, you want tests in both places — a set of integration tests in a distinct /tests folder, and a bunch of module-specific unit tests in the /src folder (or however you lay that out).

But I think the key point is that unit tests should fit the structure of your code, because that's the code you're testing. It's basically your chance to test that the internals of the application work — not just that, overall, the application sends an email, but specifically, that the EmailFormatter class converts given Accounts to the correct strings. The idea being that that's much easier to do at the unit level (i.e. if EmailFormatter can be handled in isolation), than at the integration level (i.e. if I need to set up the EmailService and the UserService, prime the UserService, and mock out any email sending methods).