niku
Parameterized testing with ExUnit
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
Most Liked
hauleth
I do not get why do you need attribute at all. Why not:
for {lhs, rhs} <- [{"one", 1}, {"two", 2}, {"three", 3}] do
test "#{lhs} convert to #{rhs}" do
assert unquote(lhs) == unquote(rhs)
end
end
8
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 ![]()
4
c4710n
That’s a metaprogramming feature - unquote fragments, which provide an easy way to generate code dynamically.
Learn more at unquote fragments.
If you are interested in metaprogramming, you can:
- grasp the basic concepts from the doc of
quote/2.- dig in depth with the book - Metaprogramming Elixir (Although it is published at 2015, the contents of it still match the current version of Elixir.)
(And, welcome ![]()
2
Popular in Guides/Tuts
Greetings: I just wrote a step-by-step guide on building a Phoenix 1.3 JWT Auth API with Guardian JWTs and Comeonin password hashing.
I ...
New
With a few questions relating to this recently, I wonder if it might help having a thread where we share how we’ve set up Elixir/Erlang/P...
New
Hello all!
For those wanting to try your hands at Elixir / Phoenix, I wrote a comprehensive tutorial on doing a simple JSON API with sai...
New
I Created a blog post about setting up svelte with phoenix.
I found it a bit tricky and the only blog post I found was written using som...
New
Warmest greetings, comrades.
I recently started using :dns_cluster (GitHub - phoenixframework/dns_cluster: Simple DNS clustering for dis...
New
Sorry if it’s a common knowledge, but it’s something I just learned and wanted to share.
I’ve seen that mind-blowing demo of hot-reload ...
New
Hey there, we’re going to walk through deploying a Phoenix app to a DigitalOcean droplet, manually - no tools no nothing. Just straight u...
New
Other popular topics
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
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
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security









