"mix test" in an umbrella

On my current project we are trying to keep our dependencies between apps in our umbrella explicit. We’ve run into situations where we get different results if we run mix test from the top umbrella level vs. running it in each individual apps’ directory. These have mostly been because some dependency was not explicit, but at the top umbrella level all the sub-apps’ modules are available when the task runs.

I’m trying to add aliases to the top level mix.exs file but I keep getting an error that the task could not be found. That implies there is some special case logic around mix tasks at the umbrella level. Can someone explain that or point me somewhere to learn about it?

Big picture, we’d like our CI server to run tests in each individual app directory so we can find out when those implied dependencies creep in. I could do it with a shell script, but I thought an alias at the umbrella level would be cleaner. I’m open to other approaches.

3 Likes

As far as I remember, mix test in the umbrella does run the sub tests in random order but in the same instance of the BEAMVM. Applications started for earlier tests won’t be shut down in-between, this may cause issues.

If you want to test the sub apps isolated to make sure that there aren’t any hidden deps, you need to iterate the sub apps with a shell script, but should be easy:

for app in apps/*; do
  pushd $app
  mix test
  pops
done
1 Like

Thanks. Yeah, that’s the sort of shell script I was thinking of, but trying to do via mix.

Upon more poking around, I figured out why my mix aliases weren’t working in the top-level mix.exs. Now I have one defined as:

    [test: "cmd mix test"]

which seems to get me what I want. I found it by digging into the exdocs for Mix and found that cmd task. Very nice.

6 Likes

What solution did you end up using here? Did you use @NobbZ’s shell script or were you able to figure it out using just mix?

@anthonator The solution hasn’t changed. I’m still happy with “cmd mix test” which is equivalent to the shell script.

1 Like

I didn’t realize that’s what cmd mix test did. Thanks for clarifying!

1 Year later this just saved me @gregvaughn

I was at a loss why mix test worked when ran from each umbrella app root but not from the top level root. This did the trick for me as well, thanks !

1 Like

Thank you for this!

Correcting a small typo: pops should be popd

for app in apps/*; do
  pushd $app
  mix test
  popd
done
2 Likes