Yonis

Yonis

How can I control every step of tests running with ExUnit

I’m developing web automation tools using wallaby.
One of the challenges in web automation is that sometimes the tests are failing for no reason and when I run it again it passes.
When I run a set of tests especially when I run it virtual machine I need a way to run a set of tests at one time and run some of them again in case of failure.

Another thing, because I’m using VM to run the tests I need a way to send messages to Slack so I can easily monitor the results.
I’m sending a few kinds of messages: before all the tests are started there is a message that the running start, before and after every test start I’m sending a message that the tests starts/ends and the result (failure/success),
finally, after all the tests completed I need to send a summary of the results.

Right now I’m managing all things with a bash file that gets the list of the tests and runs all of them one by one.
The messages before and after every test I’m sending from ExUnit formatter.

I’m looking for a better solution to manage this system without the bash file by using just the elixir system.

What I’m looking for is a way to run the all tests in one run in the order that I want and to get access to the action before the tests started between them and before they finished.

I would love your help.
THX

Most Liked

eksperimental

eksperimental

I think what you may probably need is to run your tests programmatically.

Read this thread,
ExUnit tests from a module instead of command line/mix

and the implementation of the test task in Mix. (look for the run/1 function)
elixir/test.ex at master · elixir-lang/elixir · GitHub

eksperimental

eksperimental

More on the subject,
If you are hacking Mix.Tasks.Test
read this article by @dnlserrano
dnlserrano.github.io/2019-05-26-exunit-deep-dive.markdown at master · dnlserrano/dnlserrano.github.io · GitHub

Also a recent library from @devonestes seem to do something similar.
muzak/runner.ex at 63166c0a2526cda60787c22127be8645cc13e4dd · devonestes/muzak · GitHub

I haven’t tested it, but this is this looks like the minimum code required in this test in this library.
nimler/test_all.exs at master · wltsmrz/nimler · GitHub

How did I find out all this?
https://github.com/search?q="require_and_run"&type=code

dimitarvp

dimitarvp

You don’t need to do that. You can do this in your mix.exs:

  def project do
    [
      app: :your_app,
      version: "1.2.3",
      elixir: "~> 1.14.0",
      elixirc_paths: elixirc_paths(Mix.env()),     # 👈 NOTICE THIS
      compilers: [:phoenix] ++ Mix.compilers(),
      start_permanent: Mix.env() == :prod,
      aliases: aliases(),
      deps: deps()
    ]
  end

  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_), do: ["lib"]

And then put everything that you want to have access to in tests in test/support. I don’t think you should put it in the root test/ directory however.

mhanberg

mhanberg

Creator of elixir-tools

When I run a set of tests especially when I run it virtual machine I need a way to run a set of tests at one time and run some of them again in case of failure.

If you want to retry failed tests a few times, instead of running mix test, you can run mix test || mix test --failed || mix test --failed

Another thing, because I’m using VM to run the tests I need a way to send messages to Slack so I can easily monitor the results.

Your CI provider can probably handle this for you. If you have rolled this by hand, you’ll need to build that yourself.

What I’m looking for is a way to run the all tests in one run in the order that I want and to get access to the action before the tests started between them and before they finished.

Not really sure what you’re asking here, but there are ExUnit callbacks you can hook into for different parts of the test lifecycle: ExUnit.Callbacks — ExUnit v1.11.3

kip

kip

ex_cldr Core Team

I believe if you use test --seed 0 your tests will run in the same order each time. Perhaps that will help? From mix help test:

*  --seed - seeds the random number generator used to randomize the order
    of tests; --seed 0 disables randomization

Where Next?

Popular in Questions Top

bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement