Questions tagged [ex-unit]

ExUnit is a unit testing library that ships as part of the Elixir standard library.

ExUnit Docs

117 questions
3
votes
1 answer

Elixir: Test failure messages

Using Elixir's ExUnit for unit testing, everyone seems excited about the test failure messages. However, if I am testing anything other than ==, I can't seem to get a useful error message. For example assert String.contains(my_string, "expected…
steel
  • 11,883
  • 7
  • 72
  • 109
3
votes
2 answers

Testing captured IO from a spawned process

I want to test the return value and the IO output on the following method: defmodule Speaker do def speak do receive do { :say, msg } -> IO.puts(msg) speak _other -> speak # throw away the message end …
Paul Fioravanti
  • 16,423
  • 7
  • 71
  • 122
2
votes
1 answer

Phoenix + ExUnit: where should I define global helpers?

I have using Phoenix + ExUnit for tests. I have some ExUnit.Case files like DataCase, ConnCase... to define test helpers for my Models, Controllers..., but if I need to define a global helper that it's accessible from all my tests, where should I…
rjurado01
  • 5,337
  • 3
  • 36
  • 45
2
votes
2 answers

How to test Ecto migrations

I have recently written some Ecto migrations in a Phoenix application. However, I always tested the migrations manually. As our migrations grow more complex and need to alter data on our live system, I'd really like to write automated tests before…
Mene
  • 3,739
  • 21
  • 40
2
votes
1 answer

Wallaby with headless Chrome crashes

I am developing an application based on Elixir and Phoenix which also uses the Wallaby application for HTTP based testing in a headless Chrome browser. Now recently I receive a rather unwieldy error message when executing my ExUnit tests: **…
aef
  • 4,498
  • 7
  • 26
  • 44
2
votes
1 answer

Can I split helper modules into different files using ExUnit with Mix?

A couple failed attempts and the documentation here leads me to believe that I have to either define helper modules in test/test_helper.exs or in one of the other test/*.exs files nested under a module (that use ExUnit.Case) in my mix project. Is…
matthiasdenu
  • 323
  • 4
  • 18
2
votes
1 answer

ExUnit - How to pass context to test macros in describe blocks, via named setup functions

Looking at the ExUnit documentation, you can add properties to the context struct with the following pattern: defmodule KVTest do use ExUnit.Case setup do {:ok, pid} = KV.start_link {:ok, pid: pid} # "[pid: pid]" also appears to…
Charlie
  • 4,197
  • 5
  • 42
  • 59
2
votes
2 answers

How to test the Elixir GenStage Consumer?

I found some resources on how to test the producer, however there is nothing I could find which shows how to test the Consumer. In producer, I create a dummy consumer and everything works fine, however in consumer I am struggling with…
Mr H
  • 5,254
  • 3
  • 38
  • 43
2
votes
2 answers

Marking tests in ExUnit as pending

I am looking for a way to mark tests written in ExUnit as pending. I know I can skip tests by a tag, but I am looking for a way to skip tests in a way that makes it highly transparent that these tests have been skipped because they need to be…
aef
  • 4,498
  • 7
  • 26
  • 44
2
votes
2 answers

Elixir doctest fails for function that returns random values

I have a function in Elixir that produces three random RGB tuples in a list. defmodule Color do @doc """ Create three random r,g,b colors as a list of three tuples ## Examples iex> colors = Color.pick_color() iex> colors …
Alex Fallenstedt
  • 2,040
  • 1
  • 18
  • 34
2
votes
1 answer

ExUnit Assertions

In the test cases we use assertions to handle errors. Match their return value with what we defined and the test will pass. like if we have an argument error we use this: assert_raise ArgumentError, "argument error", fn -> This will work and test…
script
  • 1,667
  • 1
  • 12
  • 24
2
votes
1 answer

Custom ExUnit assertions and pattern matching

I'm writing a flexible, adapter-based error tracking library and provide a set of custom test assertion functions to make integration tests easier to work with. I have something like # /lib/test_helpers.ex ... @doc """ Asserts specific…
Tarlen
  • 3,657
  • 8
  • 30
  • 54
2
votes
1 answer

How can I test a multiline output in Elixir?

How can I test the following code? ["one", "two", "three"]) |> Enum.each(&IO.puts(&1)) one two three :ok My test currently looks like this, but is failing because IO.puts returns :ok rather that the strings, and probably does not include newline…
FelixFortis
  • 684
  • 6
  • 16
2
votes
1 answer

Testing Ecto 2.0 in an umbrella app

I am trying to set up an app under umbrella that will handle the business logic. It uses Ecto for interacting with the database. I’m having problems with setting up SQL.Sandbox for testing. Whenever I run test, I get this error: $ MIX_ENV=test mix…
Maciej Szlosarczyk
  • 789
  • 2
  • 7
  • 21
2
votes
1 answer

** (Plug.Conn.AlreadySentError) the response was already sent

I've been studying this question with an almost identical challenge (and the answers ) - except mine is so incredibly low tech that I'm totally embarrassed at my own lack of insight <:/ System macOS 10.11.6 $ mix -v Erlang/OTP 19 [erts-8.0.2]…
walt_die
  • 580
  • 5
  • 20