joebew42

joebew42

A practical example of TDD Outside-in with Elixir

Hello :wave:

This is a follow up for the Good Elixir TDD resources? thread.

It was my intention to make a video about TDD Outside-In with Elixir, and it is finally available on YouTube. The purpose of the video is to provide a practical example, and highlight few points of the practice: test first from the outermost part of the application, baby steps and refactor as part of the process.

More resources can be found on the description of that video (recommended books, example code and further study material on this topic).

Hope this could be a valid contribution for the community, and of course I will be available to continue this discussion, and I am also alvailable to schedule a remote Pair Programming session with whoever want to practice on the same Code Kata :martial_arts_uniform:

Most Liked

Fl4m3Ph03n1x

Fl4m3Ph03n1x

Hey there!

Really nice video!
At first I was quite confused. I usually do TDD from the inside-out, I think about my application’s domain first and I test it like most people from the London school of TDD would - first I define a public API for my domain, and then as I implement it I use a recursive strategy similar to Discovery testing:

Once I have my domain fleshed out, I then proceed to adding layers on top of it, such as an HTTP layer with Plug, or a Terminal layer or something else. This architure really likes having different repos or umbrella projects. If this sounds confusing, reading my review on Designing Elixir Systems with OTP will help you understand it:

So when the video first started, I was confused. Why is he starting with HTTP first? Our application is not an HTTP app, HTTP is a detail, our app is a Greetings app. And then I got more confused when I realized both the Plug and the E2E tests were the same thing.

But as the video goes on, you actually refactor the code several times and make the division clear, eliminating and remaking tests. I really liked it. It really started making sense towards the end.

You end with Mox and Mocks. Now … This is where things get interesting for me. I have tried using Mock test doubles (not the library) for the longest time but I can’t! (PFFFF, and you call yourself a London TDDer? Shame on you!).

Hold on with the pitchforks!
I just inject my test double directly. This means, I just inject the functions I need. In other words, I inject the dependencies the SUT needs into the SUT. So, when I want to test, I just pass around 2 - 3 functions (that I stub) and I test my code that way.

The issue then is that I have a lot of configuration code lying around. I thought Mox would help, but it kinda feels like overkill, to be forced to define an interface for every module doesn’t really convince me, given the simplicity of just passing a function.

Mocks looks interesting, it looks to me like they focus more on making stubs explicit, but then again, I am still not convinced when comparing this with the simple “just pass the function you need” solution.

So this is where I am at. I must say this Outside-In journey, although different from what I am used to, was really nice and opened my eyes to E2E tests while reinforcing my notion of testing colaborators. The way you speak makes me think you have seen “Integration tests are a scam”:


TL;DR

Nice talk, make sure you watch it fully until the end or else you will miss the wrap up where most of the value and hard questioning is.

Where Next?

Popular in Screencasts Top

New
PJUllrich
For 2021, I decided to start a YouTube channel about coding with Elixir! Hurray! I learn best by teaching others, which is why I “challe...
New
ElixirCasts
I made a video to help people get introduced to agents.
New
omgneering
I made a video for getting started with the GenServer module. I introduce some concepts and try go over what's happening step by step. ...
New
SmartLogic
We at SmartLogic have been running an intermittent series of live coding sessions on Twitch that we then archive on YouTube; in the lates...
New
aseigo
In this week’s episode we look at the basics of how clustering Elixir nodes works, and how to automate their creation using libcluster (u...
New
New
omgneering
Up and Running - Elixir Phoenix on Digital Ocean A playlist of videos that go through basic app creation, getting a Digital Ocean server...
New
dokuzbir
This week i discovered Alchemist Camp youtube channel. Really good resource for elixir world. It deserves a forum topic I think channel ...
New
sjm
Hello Everyone, i hope you are doing fine! I would like to draw your attention to the Elixir Mentor YouTube channel by Jacob Luetzow. T...
New

Other popular topics Top

josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
script
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
qwerescape
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
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement