# \#unit-testing

**URL:** https://forum.elixirforum.com/tag/unit-testing/779.md

[Latest](https://forum.elixirforum.com/latest.md) · [Categories](https://forum.elixirforum.com/categories.md) · [Tags](https://forum.elixirforum.com/tags.md)

---

## [ExFuzz - Fuzz testing for Elixir is here](https://forum.elixirforum.com/t/exfuzz-fuzz-testing-for-elixir-is-here/77404)

<div class="topic-metadata">

**Author:** [@Snehil-Shah](https://forum.elixirforum.com/u/Snehil-Shah)\
**Replies:** 2\
**Last updated:** [November 17, 2026, 7:08am UTC](https://forum.elixirforum.com/t/exfuzz-fuzz-testing-for-elixir-is-here/77404 "2026-11-17T07:08:23Z")

</div>

ExFuzz is a coverage-guided fuzzer for Elixir, and I just launched v0.1.0! defmodule JasonTest do use ExUnit.Case use ExFuzz @tag timeout: 100 fuzz "Jason never crashes", data \<- binary(), seeds: \["{}", "\[1\]"\] …

---

## [Any fuzzing testing tools for Elixir?](https://forum.elixirforum.com/t/any-fuzzing-testing-tools-for-elixir/63956)

<div class="topic-metadata">

**Author:** [@Hellowman](https://forum.elixirforum.com/u/Hellowman)\
**Replies:** 4\
**Last updated:** [November 16, 2026, 6:13pm UTC](https://forum.elixirforum.com/t/any-fuzzing-testing-tools-for-elixir/63956 "2026-11-16T18:13:53Z")

</div>

Hello everyone! I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++. Does anyone knowns can i fuzz my elixir app with AFL or some similar utilities? I need to get …

---

## [Aggressive Regression](https://forum.elixirforum.com/t/aggressive-regression/76966)

<div class="topic-metadata">

**Author:** [@mudasobwa](https://forum.elixirforum.com/u/mudasobwa)\
**Replies:** 0\
**Last updated:** [October 7, 2026, 2:24pm UTC](https://forum.elixirforum.com/t/aggressive-regression/76966 "2026-10-07T14:24:57Z")

</div>

I wrote a longread on how do I test code. Everything I gained from 10 years of experience writing code without any testing and 20 years with different kinds of it. Apparently, until now there was no regression-testing …

---

## [What is a good workflow for doing TDD with Elixir?](https://forum.elixirforum.com/t/what-is-a-good-workflow-for-doing-tdd-with-elixir/75132)

<div class="topic-metadata">

**Author:** [@mr\_smith](https://forum.elixirforum.com/u/mr_smith)\
**Replies:** 3\
**Last updated:** [April 25, 2026, 3:23pm UTC](https://forum.elixirforum.com/t/what-is-a-good-workflow-for-doing-tdd-with-elixir/75132 "2026-04-25T15:23:51Z")

</div>

Hello there. I’m wondering if people have any tips for doing TDD with Elixir. I am specifically wondering if it is possible to configure mix test to only show which tests failed. I find the output to be very noisy (lot…

---

## [Broader "assert" and "refute" support?](https://forum.elixirforum.com/t/broader-assert-and-refute-support/72233)

<div class="topic-metadata">

**Author:** [@James\_E](https://forum.elixirforum.com/u/James_E)\
**Replies:** 8\
**Last updated:** [August 26, 2025, 9:08am UTC](https://forum.elixirforum.com/t/broader-assert-and-refute-support/72233 "2025-08-26T09:08:00Z")

</div>

I see that the current ExUnit source code has support for rich failure messages on a small whitelist of “recognized” assertion patterns, namely: assert match?(left, right), assert left = right refute match?(left, right…

---

## [Testing "seam" in Elixir](https://forum.elixirforum.com/t/testing-seam-in-elixir/70397)

<div class="topic-metadata">

**Author:** [@lessless](https://forum.elixirforum.com/u/lessless)\
**Replies:** 20\
**Last updated:** [August 5, 2025, 10:45pm UTC](https://forum.elixirforum.com/t/testing-seam-in-elixir/70397 "2025-08-05T22:45:06Z")

</div>

I wonder if it’s possible to mimic a simple “class reopening”/inhertinace-based SEAM in Elixir to alter a module’s behaviour without editing its code. Here is an example in pseudo-Ruby class PriceCalculator def …

---

## [Doctest: how to deal with inconsistent map key ordering?](https://forum.elixirforum.com/t/doctest-how-to-deal-with-inconsistent-map-key-ordering/71962)

<div class="topic-metadata">

**Author:** [@James\_E](https://forum.elixirforum.com/u/James_E)\
**Replies:** 8\
**Last updated:** [August 5, 2025, 5:59pm UTC](https://forum.elixirforum.com/t/doctest-how-to-deal-with-inconsistent-map-key-ordering/71962 "2025-08-05T17:59:19Z")

</div>

Considering that the order of Map keys isn’t guaranteed, is there any reliable way to check KeyErrors in doctests? Doctest failed: wrong message for KeyError expected: "key {:c, 999} not found in: %{a: 10, b: 10}" a…

---

## [Dealing with tests for projects that do a lot of side-effects](https://forum.elixirforum.com/t/dealing-with-tests-for-projects-that-do-a-lot-of-side-effects/66162)

<div class="topic-metadata">

**Author:** [@D4no0](https://forum.elixirforum.com/u/D4no0)\
**Replies:** 21\
**Last updated:** [September 19, 2024, 4:31pm UTC](https://forum.elixirforum.com/t/dealing-with-tests-for-projects-that-do-a-lot-of-side-effects/66162 "2024-09-19T16:31:06Z")

</div>

I was wondering how people usually test projects that have to rely heavily on side-effects. Imagine I have a genserver that ingests messages from RabbitMQ and has to interact with a mongodb, redis instance and maybe do …

---

## [How to create tests for System.cmd and Port when is compiling with mix](https://forum.elixirforum.com/t/how-to-create-tests-for-system-cmd-and-port-when-is-compiling-with-mix/64259)

<div class="topic-metadata">

**Author:** [@shahryarjb](https://forum.elixirforum.com/u/shahryarjb)\
**Replies:** 0\
**Last updated:** [June 17, 2024, 9:07am UTC](https://forum.elixirforum.com/t/how-to-create-tests-for-system-cmd-and-port-when-is-compiling-with-mix/64259 "2024-06-17T09:07:55Z")

</div>

Hello, I hope you are well. Two years ago I created a lib ( mishka\_installer ) that compiles a hex pkg lib in another path and move bin (builded) files to the build dir and start the apps with some considerations. Now …

---

## [Test database vs. dev database when connecting Livebook notebook to local app](https://forum.elixirforum.com/t/test-database-vs-dev-database-when-connecting-livebook-notebook-to-local-app/48852)

<div class="topic-metadata">

**Author:** [@SArthur](https://forum.elixirforum.com/u/SArthur)\
**Replies:** 4\
**Last updated:** [April 22, 2024, 3:27pm UTC](https://forum.elixirforum.com/t/test-database-vs-dev-database-when-connecting-livebook-notebook-to-local-app/48852 "2024-04-22T15:27:17Z")

</div>

I am in love with Livebook! My hope is to use it for everything from data exploration and feature planning, documentation, and TDD in a cohesive way… amazing if it comes together! On the TDD front, I have successfully c…

---

## [What are "good" and "bad" unit tests (in Elixir)?](https://forum.elixirforum.com/t/what-are-good-and-bad-unit-tests-in-elixir/61084)

<div class="topic-metadata">

**Author:** [@coen.bakker](https://forum.elixirforum.com/u/coen.bakker)\
**Replies:** 6\
**Last updated:** [January 19, 2024, 1:05am UTC](https://forum.elixirforum.com/t/what-are-good-and-bad-unit-tests-in-elixir/61084 "2024-01-19T01:05:56Z")

</div>

In an interview of José by Theo Browne, they mention the importance of “good” tests, in contrast to “bad” ones. Specifically, they started talking about this from this timestamp on. It’s not the focus of the interview,…

---

## [Ash Api testing setup (intermittent unrelated test failures in application)](https://forum.elixirforum.com/t/ash-api-testing-setup-intermittent-unrelated-test-failures-in-application/60216)

<div class="topic-metadata">

**Author:** [@zac](https://forum.elixirforum.com/u/zac)\
**Replies:** 1\
**Last updated:** [December 7, 2023, 2:23am UTC](https://forum.elixirforum.com/t/ash-api-testing-setup-intermittent-unrelated-test-failures-in-application/60216 "2023-12-07T02:23:49Z")

</div>

I’m having a hard time setting up testing for a new Ash Framework project. App details: It’s a Phoenix app, with the server boss\_site and the web app boss\_site\_web I’m just starting to build out the Ash model in a coe …

---

## [Github Actions Env variables not being read from os::env](https://forum.elixirforum.com/t/github-actions-env-variables-not-being-read-from-os-env/59949)

<div class="topic-metadata">

**Author:** [@Guelor](https://forum.elixirforum.com/u/Guelor)\
**Replies:** 0\
**Last updated:** [November 24, 2023, 6:50pm UTC](https://forum.elixirforum.com/t/github-actions-env-variables-not-being-read-from-os-env/59949 "2023-11-24T18:50:50Z")

</div>

I’m still new to GitHub action. I’m running a Phoenix/Elixir project, In my config file, I have the following configuration for the test: # Set HTTPClientMock as the HTTP client for the PayService config :sender\_service…

---

## [\`mix test --cover\` generates \`Inspect.XXX.XXX\` modules which repo does not have](https://forum.elixirforum.com/t/mix-test-cover-generates-inspect-xxx-xxx-modules-which-repo-does-not-have/59918)

<div class="topic-metadata">

**Author:** [@onurozgurozkan](https://forum.elixirforum.com/u/onurozgurozkan)\
**Replies:** 2\
**Last updated:** [November 24, 2023, 4:38pm UTC](https://forum.elixirforum.com/t/mix-test-cover-generates-inspect-xxx-xxx-modules-which-repo-does-not-have/59918 "2023-11-24T16:38:14Z")

</div>

Hi folks, When we run mix test --cover, we see some modules which starts with Inspect.XXX.XXX at cover results. mix test --cover Output Generating cover results ... Percentage | Module -----------|------------------…

---

## [Configuring an Ecto App for Testing](https://forum.elixirforum.com/t/configuring-an-ecto-app-for-testing/59334)

<div class="topic-metadata">

**Author:** [@RoboZoom](https://forum.elixirforum.com/u/RoboZoom)\
**Replies:** 5\
**Last updated:** [October 29, 2023, 8:40pm UTC](https://forum.elixirforum.com/t/configuring-an-ecto-app-for-testing/59334 "2023-10-29T20:40:50Z")

</div>

I am trying to configure a Phoenix Ecto app for testing using the example from the docs. Problem: Each time I run mix test, even when localized to a test that does not require DB access, I receive an error: 16:47:43.08…

---

## [London school TDD books?](https://forum.elixirforum.com/t/london-school-tdd-books/29662)

<div class="topic-metadata">

**Author:** [@Fl4m3Ph03n1x](https://forum.elixirforum.com/u/Fl4m3Ph03n1x)\
**Replies:** 10\
**Last updated:** [April 26, 2023, 12:27pm UTC](https://forum.elixirforum.com/t/london-school-tdd-books/29662 "2023-04-26T12:27:48Z")

</div>

Background Hey guys, recently I bought a book on TDD that I am reading. The books is really nice and has some really juicy things on architecture, but at the same time it has two main characterists I really don’t like: …

---

## [Help on how to prevent function from executing in test environment](https://forum.elixirforum.com/t/help-on-how-to-prevent-function-from-executing-in-test-environment/55286)

<div class="topic-metadata">

**Author:** [@dimitrije](https://forum.elixirforum.com/u/dimitrije)\
**Replies:** 1\
**Last updated:** [April 15, 2023, 4:25am UTC](https://forum.elixirforum.com/t/help-on-how-to-prevent-function-from-executing-in-test-environment/55286 "2023-04-15T04:25:59Z")

</div>

Hi all, I need help on how to not execute a function in test environment. I have a function which is a background supervised task which executes everytime an object is inserted/updated, because each time update/inserti…

---

## [Tzdata initialization in phoenix (in unit testing)](https://forum.elixirforum.com/t/tzdata-initialization-in-phoenix-in-unit-testing/55105)

<div class="topic-metadata">

**Author:** [@mistatwista](https://forum.elixirforum.com/u/mistatwista)\
**Replies:** 2\
**Last updated:** [April 7, 2023, 4:30pm UTC](https://forum.elixirforum.com/t/tzdata-initialization-in-phoenix-in-unit-testing/55105 "2023-04-07T16:30:49Z")

</div>

Hello, I have just started with elixir and phoenix recently with my pet project. In code I am trying to use tzdata. I have set the initialization of tzdata database in the config/test.exs import Config config :elixi…

---

## [How do I test things like IO, File, and System?](https://forum.elixirforum.com/t/how-do-i-test-things-like-io-file-and-system/54817)

<div class="topic-metadata">

**Author:** [@SeanShubin](https://forum.elixirforum.com/u/SeanShubin)\
**Replies:** 16\
**Last updated:** [March 27, 2023, 3:00am UTC](https://forum.elixirforum.com/t/how-do-i-test-things-like-io-file-and-system/54817 "2023-03-27T03:00:22Z")

</div>

New to elixir, looking for guidance regarding how to test things like IO, File, and System Whenever I learn a new language, I always make sure I know how to test it by implementing the following “Hello, world!” applicat…

---

## [Elixir unit tests next to the source file](https://forum.elixirforum.com/t/elixir-unit-tests-next-to-the-source-file/54258)

<div class="topic-metadata">

**Author:** [@andym](https://forum.elixirforum.com/u/andym)\
**Replies:** 8\
**Last updated:** [March 3, 2023, 7:31pm UTC](https://forum.elixirforum.com/t/elixir-unit-tests-next-to-the-source-file/54258 "2023-03-03T19:31:19Z")

</div>

i prefer to have my unit tests next to the source file instead of a separate folder. when i run mix test it runs the tests only within the test folder. if i remove the test folder, move the test files, and the give the…

---

## [Unit testing phoenix component gives warning](https://forum.elixirforum.com/t/unit-testing-phoenix-component-gives-warning/54221)

<div class="topic-metadata">

**Author:** [@andym](https://forum.elixirforum.com/u/andym)\
**Replies:** 3\
**Last updated:** [March 1, 2023, 9:59am UTC](https://forum.elixirforum.com/t/unit-testing-phoenix-component-gives-warning/54221 "2023-03-01T09:59:30Z")

</div>

as per Phoenix.LiveViewTest — Phoenix LiveView v1.2.5 my unit tests take the following format test "test1" do assigns = %{} name="abcd" component\_string = rendered\_to\_string(~H""" \<Web.Comp…

---

## [Mix test --cover still passes if an unit test fails](https://forum.elixirforum.com/t/mix-test-cover-still-passes-if-an-unit-test-fails/53758)

<div class="topic-metadata">

**Author:** [@andym](https://forum.elixirforum.com/u/andym)\
**Replies:** 0\
**Last updated:** [February 8, 2023, 5:59am UTC](https://forum.elixirforum.com/t/mix-test-cover-still-passes-if-an-unit-test-fails/53758 "2023-02-08T05:59:02Z")

</div>

i’m running unit tests and coverage with the following command mix test --cover the problem is that if an unit test fails and the coverage is above a threshold this command still passes. this means i need to run two c…

---

## [Mox is ignoring my Mocked module and calling the real function](https://forum.elixirforum.com/t/mox-is-ignoring-my-mocked-module-and-calling-the-real-function/53085)

<div class="topic-metadata">

**Author:** [@xgeek116](https://forum.elixirforum.com/u/xgeek116)\
**Replies:** 15\
**Last updated:** [January 11, 2023, 12:54pm UTC](https://forum.elixirforum.com/t/mox-is-ignoring-my-mocked-module-and-calling-the-real-function/53085 "2023-01-11T12:54:38Z")

</div>

I’m using using mox to help me with my unit testing (for now, I want to mock a function that fetches external API). my mix.exs : {:mox, "~\> 1.0", only: :test} My test\_helper.exs : ExUnit.start() Mox.defmock(MyApp.Mo…

---

## [Problem mocking a function when doing unit testing](https://forum.elixirforum.com/t/problem-mocking-a-function-when-doing-unit-testing/53068)

<div class="topic-metadata">

**Author:** [@xgeek116](https://forum.elixirforum.com/u/xgeek116)\
**Replies:** 2\
**Last updated:** [January 10, 2023, 8:32am UTC](https://forum.elixirforum.com/t/problem-mocking-a-function-when-doing-unit-testing/53068 "2023-01-10T08:32:33Z")

</div>

I’m testing a function that call another function to fetch external data using API calls, here is the main module code : defmodule MyApp.MyModule.ExternalData do require Logger def fetch\_external\_data(params) do …

---

## [Running ExUnit tests from iex shell](https://forum.elixirforum.com/t/running-exunit-tests-from-iex-shell/36712)

<div class="topic-metadata">

**Author:** [@bokner](https://forum.elixirforum.com/u/bokner)\
**Replies:** 7\
**Last updated:** [December 28, 2022, 4:11pm UTC](https://forum.elixirforum.com/t/running-exunit-tests-from-iex-shell/36712 "2022-12-28T16:11:45Z")

</div>

Hello everyone, I’m trying to run ExUnit tests from the shell, and I almost got it working: iex(2)\> ExUnit.start(autorun: false) :ok iex(3)\> t…

---

## [Phoenix - Unit testing without repository DB connection](https://forum.elixirforum.com/t/phoenix-unit-testing-without-repository-db-connection/50157)

<div class="topic-metadata">

**Author:** [@hauks96](https://forum.elixirforum.com/u/hauks96)\
**Replies:** 7\
**Last updated:** [November 19, 2022, 1:18pm UTC](https://forum.elixirforum.com/t/phoenix-unit-testing-without-repository-db-connection/50157 "2022-11-19T13:18:23Z")

</div>

I am trying to run unit tests in a phoenix project. The tests I am writing mock functions that call Ecto.Adapters.SQL.Query() so I do not need a database connection for the tests to succeed. When I run the tests with $ …

---

## [How to test broadcast inside terminate/2?](https://forum.elixirforum.com/t/how-to-test-broadcast-inside-terminate-2/51126)

<div class="topic-metadata">

**Author:** [@Aetherus](https://forum.elixirforum.com/u/Aetherus)\
**Replies:** 5\
**Last updated:** [October 18, 2022, 10:42am UTC](https://forum.elixirforum.com/t/how-to-test-broadcast-inside-terminate-2/51126 "2022-10-18T10:42:52Z")

</div>

For some reason, I want to broadcast a message when someone leaves a channel or disconnects due to some network issues. I wrote this code: defmodule MyAppWeb.SomeChannel do use MyAppWeb, :channel @impl true def …

---

## [Weird behavior in a test case](https://forum.elixirforum.com/t/weird-behavior-in-a-test-case/49484)

<div class="topic-metadata">

**Author:** [@nhpip](https://forum.elixirforum.com/u/nhpip)\
**Replies:** 7\
**Last updated:** [August 11, 2022, 12:08am UTC](https://forum.elixirforum.com/t/weird-behavior-in-a-test-case/49484 "2022-08-11T00:08:04Z")

</div>

Hello, I’ve been given the task to upgrade our product from OTP R22 / Elixir 1.11 to OTP R25 / Elixir 1.13.4 (hoping for 1.14). There is a test-case that works fine on 1.11 that is failing in 1.13. This is the code, as…

---

## [String validation with Regex and ExUnit](https://forum.elixirforum.com/t/string-validation-with-regex-and-exunit/49155)

<div class="topic-metadata">

**Author:** [@\_Seyed](https://forum.elixirforum.com/u/_Seyed)\
**Replies:** 6\
**Last updated:** [August 1, 2022, 12:51am UTC](https://forum.elixirforum.com/t/string-validation-with-regex-and-exunit/49155 "2022-08-01T00:51:00Z")

</div>

Hey folks, I’ve written a regular expression for validating input strings. For testing purposes, I want to setup a scenario where a set of test vectors can be automatically injected as input into a new test and match ag…

---

## [Generate %Broadway.Message{} struct to use with unit testing](https://forum.elixirforum.com/t/generate-broadway-message-struct-to-use-with-unit-testing/48939)

<div class="topic-metadata">

**Author:** [@mattmartian](https://forum.elixirforum.com/u/mattmartian)\
**Replies:** 1\
**Last updated:** [July 29, 2022, 7:01pm UTC](https://forum.elixirforum.com/t/generate-broadway-message-struct-to-use-with-unit-testing/48939 "2022-07-29T19:01:02Z")

</div>

Hi there, I’m trying to generate a list of broadway messages so that I can test a specific function within my unit tests? I can’t hardcode one as I need the acknowledger to have a PID - However I don’t want to use the Br…

[Next page](https://forum.elixirforum.com/tag/unit-testing/779.md?match_all_tags=true&page=1&tags%5B%5D=unit-testing)
