Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
77 views

How to make do:block and macros context to have the right values and variables when creating a macro in Elixir?

I’m trying to avoid redundant testing (that means, tests that are made in the same way all the time but with slightly different parameters). For example, I have this all the time when I want to test ...
Mou's user avatar
  • 2,107
0 votes
3 answers
231 views

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 ...
henhen's user avatar
  • 1,176
0 votes
1 answer
86 views

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", "...
lorem1213's user avatar
  • 464
0 votes
1 answer
171 views

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 ...
Greg M. Krsak's user avatar
0 votes
1 answer
404 views

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 ...
Peter's user avatar
  • 3
0 votes
1 answer
71 views

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 ...
José Ricardo's user avatar
0 votes
0 answers
455 views

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 ...
WilliamG's user avatar
  • 127
1 vote
1 answer
738 views

ExUnit how filter tests with two tags?

I'm running some tests using Elixir and ExUnit and I would like to pass a filter on the command line that I can select tests that have one tag but not the other. Example: Test A tags: @foo, @bar Test ...
Leonardo Gallardo's user avatar
4 votes
0 answers
247 views

How do I validate an input in elixir?

I am trying to write tests using hound and elixir and I cant seem to figure out a way to validate what was input into an input field... There is obviously a way to do this, but I have not figured out ...
Kody Berry's user avatar
1 vote
0 answers
123 views

How to preform a wait using hound/elixir?

I am trying to wait for an element to appear on the page after a button click, but cant figure out how to wait for that element... I know there is the :timer.sleep(100), but whenever I use this I get ...
Kody Berry's user avatar
1 vote
2 answers
110 views

Elixir: Integration test false positive, why is it failing and how to prevent further false positives?

I'm just starting in Elixir, so I'm risking asking something that should be straight forward. I'm sorry if that's something that should be so obvious or easy. I'll omit some code to keep the question ...
jacksonbenete's user avatar
1 vote
0 answers
529 views

Cleanup ExUnit from within the same process (unlike on_exit)

In our codebase, we have lots of tests that involve interacting with the database (via Postgrex). We have a handful of shared ExUnit.CaseTemplates whose setup hook prepares the Ecto sandbox and such, ...
s3cur3's user avatar
  • 2,985
1 vote
1 answer
208 views

How to run ExUnit tests with erlang debugger?

Background I have a small function with some branching logic and I have some tests for it. I would like to use the erlang debugger when I run a given test to make sure I am executing the correct code. ...
Flame_Phoenix's user avatar
0 votes
1 answer
487 views

Verifying struct keys presence in tests

assert Contract.fetch(contract: valid_address) == %Contract{ contract: "0x3D29Aa78fB558F84112bbC48a84F371147A920C9", name: "bla", price: nil, ...
John Smith's user avatar
  • 1,866
1 vote
1 answer
427 views

How to use render_change result to match specific element?

I'm testing LiveView form with render_change/2 html = view |> element("#filter-form") |> render_change(%{filter: %{days: "14"}}) The result I get is a string ...
achempion's user avatar
  • 794
0 votes
1 answer
256 views

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 = [ "...
rwehresmann's user avatar
  • 1,148
3 votes
1 answer
788 views

Stop a GenServer after each test

Background I have a set of tests that need a GenServer to be started before. As a rule of thumb, I understand it is a good practice to cleanup after each test, so I also want to stop the GenServer ...
Flame_Phoenix's user avatar
1 vote
1 answer
220 views

How to spawn a cowboy server in a test?

Background I have a specific test where I need to spawn a cowboy server listening on port 8082 that returns some static responses. Objective Normally I would spin up a cowboy process in my application....
Flame_Phoenix's user avatar
1 vote
1 answer
1k views

Prevent "GenServer terminating" error in exunit test with supervised process

I have a test in my Phoenix app that is testing a Phoenix.PubSub subscriber that uses Genserver. The subscriber does some database work as part of its handle_info/2. test "sending creating a ...
harryg's user avatar
  • 24k
0 votes
1 answer
2k views

Ecto assert #Ecto.Association.NotLoaded<association :xyz is not loaded>

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) == ...
Joe Eifert's user avatar
  • 1,387
0 votes
2 answers
142 views

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's user avatar
  • 56
0 votes
0 answers
169 views

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 ...
Daniel F Jaramillo's user avatar
0 votes
1 answer
675 views

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 ...
Châu Hồng Lĩnh's user avatar
0 votes
1 answer
274 views

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....
Christopher Simmons's user avatar
3 votes
2 answers
165 views

Check all test files are compilable

I have a case when I need to check that all files in my app's test suite are compilable. I'm trying to create a list of all files and then compile them, but it turns out I can't do it without ...
denis.peplin's user avatar
  • 9,823
0 votes
1 answer
177 views

How to write ExUnit test cases in elixir for an escript project

I have an escript project done in Elixir using mix. The project has two or three .ex files that needs to be executed using certain arguments using the "escript" command It is like a client server ...
Skadoosh's user avatar
  • 717
2 votes
1 answer
685 views

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'...
rjurado01's user avatar
  • 5,495
2 votes
2 answers
2k views

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, ...
Mene's user avatar
  • 3,799
1 vote
1 answer
89 views

How to get the status of tests in my file using hound?

ExUnit provides some methods to get test result. I am not sure how to use it https://hexdocs.pm/ex_unit/ExUnit.Test.html and https://hexdocs.pm/ex_unit/ExUnit.Formatter.html. I have multiple tests in ...
LearningNewTech372923's user avatar
1 vote
1 answer
1k views

How to test GenServer restart behaviour?

In my app I have a GenServer. It backs up data needed to start again in an Agent. I want to test if my GenServer backs up and restores correctly, so I wanted to start backup agent, then restart ...
VOID404's user avatar
  • 35
0 votes
3 answers
828 views

Use ExUnit to test CLI Elixir script

I'm writing a single exs file Elixir script (not using mix). The script contains a module, as well one function call in the outer scope that starts accepting input from stdin and sends it to the ...
Jeremiah Rose's user avatar
1 vote
1 answer
1k views

How to clean test DB after **all** test complete?

I have a module of tests that run synchronized one after the other. I would like to clean all the changes done on the db by the tests after all tests complete, i.e. I want the data to persist in the ...
faigy langsam's user avatar
0 votes
1 answer
130 views

Weird error which shows up *sometimes* in tests in Elixir using Ecto

Error: 14:18:04.259 [error] GenServer MyApp.Receiver.Handlers terminating ** (Ecto.Query.CastError) deps/ecto/lib/ecto/repo/queryable.ex:382: value `1234` in `where` cannot be cast to type :string ...
GenericJam's user avatar
  • 2,995
1 vote
1 answer
794 views

Enum.each loses variable when looping over an ExUnit test

When running the following code I get the warning: warning: variable "char" does not exist and is being expanded to "char()", please use parentheses to remove the ambiguity or change the variable ...
kingsfoil's user avatar
  • 3,875
3 votes
2 answers
481 views

How can I use Elixir's doctest to test a protocol implementation?

I want to be able to doctest the implementation of a protocol in Elixir. Here is some example code: defprotocol Size do def size(data) end defmodule Foo do defstruct [] defimpl Size do @...
jonleighton's user avatar
  • 1,051
0 votes
2 answers
553 views

In Elixir ExUnit, how do I guarantee that the Supervisor will create a new GeNserver?

I'm learning to test in Elixir and this problem appeared: When I run the following test, sometimes it passes and sometimes don't, I'm thinking it is the fact that the Supervisor don't have the time ...
Mateus Luiz's user avatar
1 vote
1 answer
228 views

How do I write an Elixir doctest to verify an empty MapSet

Just learning about doctests in Elixir and I'm trying to write an Elixir doctest to verify that a struct will contain two empty MapSets. defstruct [:coordinates, :hit_coordinates] @doc """ Creates ...
BrianB's user avatar
  • 424
1 vote
1 answer
54 views

How do I fail the CI when there is an `@tag` in a test?

We often have comments in our code review that tells people to remove their @tag from tests they had tagged to have a tighter iteration loop. However, I think that is a waste to have depend on humans ...
CallMeNorm's user avatar
  • 2,545
2 votes
1 answer
608 views

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 ...
aef's user avatar
  • 4,648
0 votes
2 answers
370 views

How to hide logs in some tests but not in others?

Background I have library that logs messages depending on the value of disable_logging: unless Application.get(:my_app, :disable_logging, false), do: Logger.info("Hello World!") Depending on ...
Flame_Phoenix's user avatar
0 votes
1 answer
105 views

In this ExUnit test runner, why is ExUnit.Server.modules_loaded() called here?

So when running ExUnit with the stale option, why is this line ExUnit.Server.modules_loaded() called? I think this line Kernel.ParallelCompiler.require(test_files, parallel_require_callbacks) is ...
Nona's user avatar
  • 5,402
2 votes
1 answer
510 views

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 ...
matthiasdenu's user avatar
0 votes
1 answer
294 views

Handling error for large queries and sending 413 response

I have a voice note upload function. I was writing tests and as part of it I wrote the following test for larger files where I want to have it throw a 413 Entity too large error: test "send VN fail ...
Omar Hussein's user avatar
  • 1,147
0 votes
1 answer
79 views

ExUnit.CaptureIO still waits for input on multiple IO.read calls

Consider the following minimal [?] example: defmodule Foo do def bar() do n = IO.read(:line) |> String.trim() |> String.to_integer() for _ <- 0..n - 1 do IO.read(:line) |> ...
a small orange's user avatar
0 votes
1 answer
73 views

ExUnit triggers Empty Error with setup_all block

I have a test which requires preinserted data. So I am trying to setup those data with setup_all callback as those data can be setup once. Since I do not want to assign anything to context, I ...
D.R's user avatar
  • 859
3 votes
1 answer
720 views

Force Hackney request timeout in test

I'm looking for a way to be able to reproduce a Hackney HTTP POST request timeout in one of my controller tests. I'm also using ExVCR, but that doesn't seem to allow you to force a request timeout ...
Peter Brown's user avatar
  • 51.6k
0 votes
1 answer
422 views

Cyclic dependency in test cases

I have three apps in umbrella project setup Datalayer ApiLayer OtherLayer Some Other layer(but mandatory) Now I have dependencies defined like this in mix file App ApiLayer has {:OtherLayer, ...
Radio Active's user avatar
2 votes
1 answer
2k views

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,...
Charlie's user avatar
  • 4,290
0 votes
1 answer
417 views

Writing doctests when a struct is returned

An answer to a similar question has this question. In order to test a function with doctests, you must be able to predict the output of your function. Issue As mentioned in the title I would ...
shmink's user avatar
  • 301
1 vote
1 answer
1k views

Is it possible to not load associations after insertion with ExMachina? [duplicate]

I'm using ex_machina to create fixture for my unit-tests. I'm saving some records to the database using ExMachina insert(:comment) but my assertions are wrong because ExMachina always load relations ...
samidarko's user avatar
  • 612