ExUnit is a unit testing library that ships as part of the Elixir standard library.
Questions tagged [ex-unit]
117 questions
1
vote
1 answer
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 B tags: @foo
I'd like to run just the test B…

Leonardo Gallardo
- 45
- 4
1
vote
0 answers
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 the following error.
20:17:56.605 [error]…

Kody Berry
- 111
- 1
- 7
1
vote
2 answers
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 concise, the code is actually for the exercise on…

jacksonbenete
- 159
- 1
- 9
1
vote
0 answers
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, and this works great.
The problem I'm running…

s3cur3
- 2,749
- 2
- 27
- 42
1
vote
1 answer
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.
Code
Lets assume we are testing…

Flame_Phoenix
- 16,489
- 37
- 131
- 266
1
vote
1 answer
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 containing rendered html.
I want to assert that the result has some specific…

achempion
- 794
- 6
- 17
1
vote
1 answer
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.ex file like this:
def start(_type, args) do
…

Flame_Phoenix
- 16,489
- 37
- 131
- 266
1
vote
1 answer
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 referral code upon user registration" do
…

harryg
- 23,311
- 45
- 125
- 198
1
vote
1 answer
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 a file. How can I generate results at the end…
1
vote
1 answer
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 GenServer and see if it works (remembers config from…

VOID404
- 25
- 4
1
vote
1 answer
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 db between one test to another.
My app is using a…

fay
- 2,086
- 2
- 14
- 36
1
vote
1 answer
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 name
test/my_module_test.exs:7
Followed by a…

kingsfoil
- 3,795
- 7
- 32
- 56
1
vote
1 answer
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 a new Island structure
## Examples
iex>…

BrianB
- 424
- 2
- 13
1
vote
1 answer
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 to make those comments.
Is there some option for…

CallMeNorm
- 2,299
- 1
- 16
- 23
1
vote
1 answer
Is it possible to not load associations after insertion with ExMachina?
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 and it's not the case when I'm fetching with Ecto…

samidarko
- 590
- 7
- 20