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
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
I wrote a small article on how to use current_user with coherence on Phoenix. There are already a couple of blogposts about it but I thin...
New
Some time ago someone suggested me to write article about how I have configured my Vim to work with Elixir, now there it is:
https://med...
New
So here is the code I came up with to generically generate an array param that will be stored on a jsonb property in ecto.
It only handl...
New
Whenever tests have to interact with an Ecto.Repo, sometimes it’s necessary to test a few different branches or paths that data can take....
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
Hey, today I give amnesia library a try and found a few problems. I would like describe how to setup it properly and solve problems which...
New
Just a quick heads up: There seems to be a bug in Erlang/OTP 21.3, which can cause some errors when making http requests. If you’re using...
New
We finally have a Mix clustering guide to go with Phoenix deployment with Mix Releases.
Deploy an Elixir Cluster with Mix Releases and l...
New
I have published an elixir project with using Travis CI.
I would like to share some tips & thoughts that I was getting through this ...
New
Other popular topics
Hi! May someone helps me, please!
I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
Phoenix 1.4.0 released
Phoenix 1.4 is out! This release ships with exciting new features, most notably
with HTTP2 support, improved deve...
New
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New







