Questions tagged [ex-unit]

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

ExUnit Docs

117 questions
1
vote
2 answers

ExUnit mock sequence

Is it possible to mock a sequence of return values with ExUnit Mock the same way meck provides this functionality in Erlang? ... meck:new(my_module), meck:sequence(my_module, method, 1, [Response1, Response2]), meck:unload(module), ... If not, is…
David
  • 595
  • 1
  • 8
  • 19
1
vote
1 answer

How to run real phoenix server during test?

I'm implementing kinda tricky functionality with external libraries I can't mock. They needs to implement real requests to the server. So, how can I run a web-server during tests implementation? P.S. My config/test.exs: config :my_reelty,…
Alex Antonov
  • 14,134
  • 7
  • 65
  • 142
0
votes
3 answers

Writing a unit test for a specific elixir function task (parsing then sorting)

I am new to elixir and trying to learn some of it's features including the testing library ExUnit, but I am having some trouble understanding the concept of how to write and setup a test for a particular function and if I am going in the correct…
henhen
  • 1,038
  • 3
  • 18
  • 36
0
votes
1 answer

Running tests from top to bottom

defmodule GroupTest do use ExUnit.Case alias Chat.CentralServer, as: Server alias Chat.Client, as: Client @clients ["lorem", "john doe", "friend24", "tempname2434"] @groups ["synergy_squad", "The Rhinos", "guffsuff"] setup do :ok …
lorem1213
  • 433
  • 4
  • 11
0
votes
1 answer

Elixir: VS Code ExUnit cannot find Mix

I cannot load or run my tests, from within VS Code. I'm a new user to Elixir, and to VS Code. I'm running Lubuntu 21.10 (Impish). I've downloaded Erlang/OTP 25 (.deb), and Elixir 1.14 (precompiled binary in /usr/share/elixir), and can get anything I…
0
votes
1 answer

Why can't I import test modules directly into other tests in elixir

I spent days trying to figure out how to import my test modules into a master test module so I could run them synchronously and I finally found my solution at the link below: Importing test code in elixir unit test My question is - WHY does this…
Peter
  • 3
  • 2
0
votes
1 answer

Is it possible to color format string comparisons inside of a Mox expectation?

when a string equality assertion fails in an ExUnit test case, a color-formatted output is provided. Eg., for: test "my test" do assert "xyz" == "xwz" end we get But when I do it inside of expect/4: test "my test" do expect(MyMock, :post, fn…
José Ricardo
  • 1,479
  • 1
  • 14
  • 28
0
votes
0 answers

Elixir mox - mocking service used by genserver

I'm using Mox to mock a service Pokemon.Api (mock is called Pokemon.ApiMock) and everythings works fine. I have also created a custome ExUnit.CaseTemplate(Pokemon.Case) and am stubbing the mock implementation with the real implementation. So if I…
WilliamG
  • 127
  • 2
  • 8
0
votes
1 answer

Verifying struct keys presence in tests

assert Contract.fetch(contract: valid_address) == %Contract{ contract: "0x3D29Aa78fB558F84112bbC48a84F371147A920C9", name: "bla", price: nil, price_bnb: nil, call_id: 7, symbol: nil, …
John Smith
  • 1,726
  • 2
  • 18
  • 30
0
votes
1 answer

How to assert inside a pipeline in Elixir ExUnit.Case (Elixir)

I have the following test that is working: test "accepts a request on a socket and sends back a response (using tasks)" do spawn(HttpServer, :start, [4000]) urls = [ "http://localhost:4000/products", …
rwehresmann
  • 1,108
  • 2
  • 11
  • 27
0
votes
1 answer

Ecto assert #Ecto.Association.NotLoaded

I usually check if my test returns the expected result like this: company = company_fixture() # inserts a company in the database with default attributes assert Profile.get_company!(company.id) == company But this fails Assertion with ==…
Joe Eifert
  • 1,306
  • 14
  • 29
0
votes
2 answers

How to send test results to another place on elixir

When I run mix test I get all the results back in the shell. How can I get the results to more places like slack, files etc..?
Yoni S
  • 36
  • 1
  • 7
0
votes
0 answers

Configure Retry for Wallaby or ExUnit

Currently I'm developing browser tests but sometimes they are flaky so I want to add retry to those tests, Idk if there is an easy way to add retry to a project with Wallaby and ExUnit by configuration or if there is an library out there. Thanks
Daniel F Jaramillo
  • 413
  • 1
  • 5
  • 12
0
votes
1 answer

Phoenix with exq: How do I execute mix test without redis running

I use exq in my Phoenix application with Phoenix 1.4.16 to run some background jobs. One of them can be as simple as this: defmodule PeopleJob do def perform(request) do IO.puts("Hello from PeopleJob:\n#{inspect(request)}") end end It runs…
Châu Hồng Lĩnh
  • 1,986
  • 1
  • 20
  • 23
0
votes
1 answer

How to add information to ExUnit's output for failing tests

My tests' ExUnit.Callbacks.setup function creates an ID that I want to include in ExUnit's output when a test fails. Is there a simple way to do this? I know that I could write a custom ExUnit.Formatter, but that seems like overkill. The context of…