archan937
ExUnited - Easily spawn Elixir nodes (supervising, Mix configured, easy asserted / refuted) within ExUnit tests
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
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly.
One of i...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Other Trending Topics
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
We want to introduce a new native datatype to Erlang: native records. Although replacing all tuple records with native records is not our...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog
It says that Fly is going all-in on sprites, which is a worry ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance










First 2 of 2 Posts
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.