Questions tagged [ex-unit]

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

ExUnit Docs

117 questions
0
votes
1 answer

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 based project where one escript run, starts the…
Skadoosh
  • 699
  • 2
  • 11
  • 27
0
votes
3 answers

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 module functions. I also have a second file that…
Jeremiah Rose
  • 3,865
  • 4
  • 27
  • 31
0
votes
1 answer

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 in query: from c0 in MyApp.DB.Client, where:…
GenericJam
  • 2,915
  • 5
  • 31
  • 33
0
votes
2 answers

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 to restart the GenServer: test "Supervisor will…
Mateus Luiz
  • 756
  • 7
  • 20
0
votes
2 answers

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 MIX_ENV I have a config for each…
Flame_Phoenix
  • 16,489
  • 37
  • 131
  • 266
0
votes
1 answer

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 needed to require the ex_unit test files to be able to…
Nona
  • 5,302
  • 7
  • 41
  • 79
0
votes
1 answer

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 when too large", %{conn: conn} do …
Omar Hussein
  • 1,057
  • 2
  • 13
  • 31
0
votes
1 answer

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) |> IO.write() end end end import…
a small orange
  • 560
  • 2
  • 16
0
votes
1 answer

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 defined setup_all like below setup_all do …
D.R
  • 829
  • 4
  • 16
  • 30
0
votes
1 answer

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, in_umbrella: true}, {:Datalayer, in_umbrella: true} App…
Radio Active
  • 449
  • 6
  • 18
0
votes
1 answer

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 like to stick with using doctests but this doesn't…
shmink
  • 189
  • 1
  • 3
  • 12
0
votes
0 answers

How to have multiple assertions in an ExUnit doctest

I am trying to write the majority of my tests in documentation. They form a very helpful set of documentation. Several of the tests have a moderate amount of setup and it would be cleanest if I could have several assertions in the doctest. I tried…
Peter Saxton
  • 4,466
  • 5
  • 33
  • 51
0
votes
1 answer

Check status code with ExUnit failed, but actual REST test success

I'm writing a controller function where it will check for a condition ( keyword to be valid ) before either to render a json object or error object if failed. router.ex scope "/api", DongNghiaWeb do pipe_through :api scope "/tim_kiem" do …
0
votes
2 answers

Phoenix controller test case loses current_user

I'm facing the problem where all tests in which I need to assert more than one thing with a logged in user, it seems that it loses the saved session. I have a setup code which assigns a fixture user before each test: setup %{conn: conn} = config do …
thyago stall
  • 1,654
  • 3
  • 16
  • 30
0
votes
1 answer

Use ExUnit.Assertions inside macro

I have written a small macro for test cases. defmodule ControllerTest do @required [:phone, :country] defmacro create(fields) do quote do without = length(unquote(@required) -- unquote(field) if without !=…
script
  • 1,667
  • 1
  • 12
  • 24