i prefer to have my unit tests next to the source file instead of a separate folder. when i run mix test it runs the tests only within the test folder. if i remove the test folder, move the test files, and the give the following configuration in the mix.exs configuration
test_paths expects a list of path, so ["."] should work. But you need a test_helper.exs file in your project directory then.
Also not sure why you want to break with the convention as it makes it hard for other people to find your test and understand your project.
I completely agree with you. And I would add another point. Having them next to the module which is tested, has three more advantages:
I use tests as a documentation tool. They are nice code examples and often better transfer meaning than words. When a library does not have extended documentation, but a good test suite, it helps to check it out.
Code / test navigation is much easier, as you do not have to switch between deeply nested folders.
When remove obsolete modules, with colocated tests, you only have two remove 2 files or a folder. No need to search in multiple places.
The only thing which is bugging me, that for integration or e2e tests, you still need a test folder or something similar to it.
Right now, I stay with elixirs / phoenix default structure and put all tests in the test folder. But I would still prefer to have them colocated
When remove obsolete modules, with colocated tests, you only have two remove 2 files or a folder.
Well not really, do you write only unit tests? While I agree with you that in regard of unit tests for functions in a module this is the case, when doing higher level tests of your system, having the test file linked to a module will not help you much, if at all.
This must be a people who use tree-explorers for navigation versus those who don’t. Any semi-decent modern editor is going to have a “jump to test file and back” hotkey so finding 1:1 tests is a non-issue. I do use a tree-explorer but it’s primarily for getting an overview of module structure so I find it so noisy with file names doubled-up most of the time.
I could bikeshed on this forever so I’ll leave it at that