Elixir/Phoenix How You Can Cut Test Time by 80% With Development Specific Test Suites.

How to Profile Your Test Suite.

To speed up your test suite, you need to know the largest areas to improve. Likewise, you need to know your slowest test.

Photo by Tim Gouw on Unsplash

Use Mix to Find Your Slowest Tests.

You can run your tests and return a list of your N slowest tests, where N is the number of tests you want to display.

mix test --slowest N
mix test --slowest 100

Tag Expensive Tests.

You can tag modules, describe blocks, and individual tests in elixir using @moduletag, @describetag, and @tagIf you want to know more, you can read my article Phoenix/Elixir testing: beyond mix test.

Exclude Expensive Tests

By tagging your tests, you have control over which tests you want to run. For example, you can exclude the expensive tests by using the --exclude flag.

mix test --exclude="expensive"

Didn’t You Just Ignore Longer Tests?

Yes. Absolutely, you are right. However, in most cases, you don’t need 100% test coverage. You make a small change and want to be reasonably sure that you didn’t break anything.

Run You Fast Tests Before Your Slow Tests.

You can still run the full test suite before you push your branch. For example, I added the following commands to our pre-push hooks that run before anyone pushes their finished code.


Using the slowest flag to profile your test suite allows you to create a development-specific suite of tests to save time.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Brooklin Myers

Brooklin Myers

Software Engineer. I create educational content focused on technology for mobile and web applications.