Alex Antonov
Alex Antonov

Reputation: 15216

How to implement some command before ExUnit test with some tag starts

I have a test suite which uses wallaby library which needs a heavyweight webpack build for usage. The problem is that I this webpack build is too heavy to use it before only model test, for example.

So, I decided about this feature:

  1. Tag all wallaby tests with some tag, ie: @tag :wallaby
  2. Check if there is at least one tagged by wallaby test exists for running test suite
  3. If so, wait for the build and then run the whole test suite.

Is it the best design? How can I implement it?

Upvotes: 0

Views: 218

Answers (1)

tkowal
tkowal

Reputation: 9299

According to "Test Pyramid" you shouldn't have many UI tests and you should run them rarely, because they are slow and expensive.

One approach would be to exclude the wallaby tag from your unit tests by adding this to your test_helpers:

ExUnit.configure exclude: [:wallaby]

Now running mix test won't run any UI tests until you run it with --include:

mix test --include wallaby

This approach is better than hook before wallaby tag, because it is explicit and developer won't be surprised by long running build and integration tests.

It might be also good idea to add mix alias in mix.exs which starts the webpack build and runs the wallaby test. It will be single command that can be used in CI.

Upvotes: 0

Related Questions