Ensure that tests have an .exs ending

It is sometimes the case that developers create a test file with .ex ending, and it is then skipped by ExUnit.

Is there a way to prevent this? Like throwing an error if the pattern _test.ex was found in a filename. I am thinking about writing a custom Credo check, but maybe there is something already.

One approach is to add a test that looks for any files in the test folder that don’t end in _test.exs. You’d have to ignore test/support but that should be pretty easy. I’ve thought about this but haven’t done it. Although I have been bitten by this exact problem in the past.

3 Likes

That should probably be a git commit hook: abort if any staged file matches the _test.ex pattern.

3 Likes

Created a PR for Credo. https://github.com/rrrene/credo/pull/821

Let’s see if it will get accepted. Would really like to have something that I can reuse in all projects without extra setup.

1 Like