niku
I write an article Parameterized testing with ExUnit.The key concept is using ExUnit.Case.register_test/4 such as
ExUnit.start()
defmodule ParameterizedTest do
use ExUnit.Case, async: true
ExUnit.Case.register_attribute __ENV__, :pair
for {lhs, rhs} <- [{"one", 1}, {"two", 2}, {"three", 3}] do
@pair {lhs, rhs}
test "#{lhs} convert to #{rhs}", context do
{l, r} = context.registered.pair
assert l === r
end
end
test "pair should not have any value" do
assert nil === @pair
end
end
Trending in Guides/Tuts
Other Trending Topics
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
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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
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
- #blog-post
- #ai
- #phoenix_html
- #iex
- #graphql
- #elixirconf-us
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
hauleth
I do not get why do you need attribute at all. Why not:
niku
Because I have never thought it until you mentioned.
It seems the code that you write is more smarter than I write. I use it.
Thanks a lot
kazlu
I know this is an old forum, but I’m super new to elixir and I’d like to know why this works.
Thanks in advance.
c4710n
That’s a metaprogramming feature - unquote fragments, which provide an easy way to generate code dynamically.
Learn more at unquote fragments.
(And, welcome