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
1 answer

Elixir ExUnit: Run function before the complete test suite?

There is the setup callback that is invoked before each test and the setup_all callback that is invoked only once per module, before any test runs. I have the situation where I need to prepare something before the whole test suite runs. Only once. I…
Ole Spaarmann
  • 15,845
  • 27
  • 98
  • 160
1
vote
1 answer

Unable to assert SyntaxError in ExUnit

Here is the code I am testing: defmodule BracketParser do @spec parse_line(binary) :: binary def parse_line(line), do: parse_line_as_list(String.graphemes(line), false, []) defp parse_line_as_list([], true, _acc) do …
dopatraman
  • 13,416
  • 29
  • 90
  • 154
1
vote
1 answer

Overridable Macro for exunit test cases

I am writing test cases for my application and most of my controllers contain common code for CRUDs so I have written common macro and use it inside my controllers. Test cases for all of the controllers would be written automatically. But I am…
Radio Active
  • 449
  • 6
  • 18
1
vote
1 answer

Hound ExUnit: assert_raise seems to considerably slow down the test suite

I've added the following test for a phoenix application: navigate_to("/") registration_page_link = find_element(:class, "header__button__register") registration_page_link |> click() form = find_element(:class,…
David B.
  • 788
  • 1
  • 11
  • 21
1
vote
1 answer

In Elixir how to mock temporary failures

I am mocking an HTTP call (using Tesla) with Mox like this: test "Token expiry is handled by re-applying for a token on the fly", %{conn: conn} do TeslaMock |> expect(:call, 8, fn env, _opts -> case env.url do …
raarts
  • 2,711
  • 4
  • 25
  • 45
1
vote
1 answer

ExUnit config: starting tests without supervision tree

I'm trying to imitate separate Unit and Integration tests in Elixir project. For Unit tests I don't need Supervision tree running, so ideally I'd like to use something like module tag, i.e. @moduletag :integration which would group tests that…
Ivan Yurov
  • 1,578
  • 10
  • 27
1
vote
1 answer

Phoenix simple auth testing logged in user

From this Simple authentication tutorial I am looking to test routes of the app inside the :login_required pipeline (which simply checks if the client has called Guardian.Plug.sign_in(conn, user)) As the user_path show action needs to have been…
Sam Houston
  • 3,413
  • 2
  • 30
  • 46
1
vote
1 answer

How to read new Phoenix channel instance's state in Channel test case?

I have the following phoenix channel that handle an incoming message, broadcasts it and then updates the channel instance's socket state: defmodule MyApp.MyChannel do use MyApp.Web, :channel def join("topic", _payload, socket) do {:ok,…
1
vote
1 answer

Elixir ExUnit test with custom dependency environnement

I have a project A, which depends on a dependency B created by me also... when I want to launch test on A with a simple mix test, it's getting the dependecy B, compiling it and starting it in :prod environnement... Which mean A is in :test…
TheSquad
  • 7,385
  • 8
  • 40
  • 79
1
vote
1 answer

Testing/Validating Factory changesets & Repeatable Schema Testing in ExMachina

This isn't an issue, I just wanted to make sure that this code is having the effect for testing that I think it is having. I want to have a test that builds/creates the struct via the factory and check to make sure the changeset is valid, much like…
DogEatDog
  • 2,899
  • 2
  • 36
  • 65
1
vote
1 answer

Elixir: Redefine module in test

I have an ExUnit test that pings an endpoint. That endpoint calls a function that makes an external call via an http client that is determined by the environment a la Jose Valim's famous post. In the test environment, I'm using a mock module of…
steel
  • 11,883
  • 7
  • 72
  • 109
1
vote
1 answer

Make fixtures and testhelp functions available for ExUnit and iex

I am writing a project that I want to test, both automatically with ExUnit and interactivly with iex. Say my project look like this: [mto@bgobuildwin8g sample]$ tree . ├── config │   └── config.exs ├── fixtures │   └── complex_struct.exs ├── lib │  …
toftis
  • 1,070
  • 9
  • 26
1
vote
1 answer

Issue with integration testing web application in umbrella

I am working on a phoenix application. This application is part of an umbrella app. In this umbrella I have small applications responsible for different areas for the application, which are: phoenix web api ("api") core business logic ("core") user…
Thorakas
  • 135
  • 5
1
vote
0 answers

How to test a function that converts one file type to another

I'm working on a small escript app that converts ebook formats (.pdf, .epub) into the .mobi format for use on a Kindle, and I'm wondering how (using ExUnit) I can test that a conversion was successful without actually running the code on a real file…
FelixFortis
  • 684
  • 6
  • 16
1
vote
1 answer

Mix warns me about an undefined module the first time I compile in my test environment. How to ignore it?

I have a module defined in my test/ directory which is used to mock the function :crypto.strong_rand_bytes/1 which outputs random values. In my test configuration I replace the "module" containing the function like so: config :lottosim, :crypto,…
diogovk
  • 2,108
  • 2
  • 19
  • 24