archan937
Hi all,
ExUnited is a Hex package designed to easily facilitate spawning supervising local Elixir nodes within tests. Unfortunately, I was not able to properly setup a spawned node for supervisioning with the Erlang :slave.start_link/1 function. So I have written ExUnited to accomplish that, along with supporting Mix.Config configurations, additional loaded code, and a developer friendly way of writing assertions and refutations in the context of a spawned node which really improved the readability of the tests and more.
Features
- Spawn nodes for testing purposes
- Spin up “partially connected” vs “fully connected” nodes
- Run in “verbose” mode which prints a colorized STDOUT of the nodes
- Specify extra “code paths” which will be included (
config.exsincluded) - Support child supervisioning within a spawned node
- Exclude certain dependencies for spawned nodes
- Easily assert and refute within the context of spawned nodes
Example
defmodule MyNodeClusterTest do
use ExUnited.Case
setup do
{:ok, spawned} =
ExUnited.spawn(
david: [code_paths: ["test/nodes/beckham"], supervise: [David]]
)
on_exit(fn ->
ExUnited.teardown()
end)
spawned
end
test "executes code in spawned node", spawned do
assert :"captain@127.0.0.1" = Node.self()
refute :"david@127.0.0.1" == Node.self()
sentence = "The only time you run out of chances is when you stop taking them."
as_node(:david, phrase: sentence) do
assert :"david@127.0.0.1" = Node.self()
refute :"captain@127.0.0.1" == Node.self()
assert ^phrase = David.talk()
foo = :bar
refute match?(%{node: ^foo}, %{node: :foo})
end
end
end
See full example.
Enjoy the package! I would love to receive a shoutout and/or your feedback ![]()
Trending in Announcing
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries.
offset-based pagination with...
New
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi all!
I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas.
You...
New
Hello
Published a new library - ProcessHub!
ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
This showed up on my feed.. anyone heard of it? Just hype?
Ox Alpha is a reasoning model designed for coding, sustained ag...
New
It’s not that it’s vocabulary is too advanced. It’s something worse.
I get lost trying to follow even a paragraph written by Claude. It’...
New
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
archan937
I just released ExUnited v0.1.1 containing the following enhancements:
:excludeoption for individual spawned nodesarchan937
ExUnited v0.1.2 has just been released:
MIX_ENVwhen spawning nodes (solvesmeckrelated testing problems)ExUnitThe README fragment concerning the
mix_envconfiguration:ATTENTION: When also using meck-based packages
The following errors can occur when also using packages like mock or MecksUnit (which both use the Erlang library meck to mock functions) and spawning the nodes with the default environment
test:(UndefinedFunctionError) function Some.Module.some_function/1 is undefined(ErlangError) Erlang error: {{:undefined_module, < Some.Module >}To tackle this, you should configure any other (Mix) environment to spawn the nodes with. Configure it like so:
You might also want to consider using a bogus environment (e.g.
:void) to skip the non-relevant:devdependencies, likecredoordialyxirprobably. That will save some compile time.And last but not least, please note that using a different environment within CI builds will require compiling the project in that particular environment on beforehand of the tests. Otherwise spawning the nodes will take too much time and that will cause timeout errors during the tests.