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

AlchemistCamp
https://alchemist.camp/episodes/word-count I’ve just made a new version of of Lesson 2 from Alchemist Camp. It has significantly larger ...
New
sevensidedmarble
New video on LiveView for almost total beginner level: Hopefully this is a helpful starting point for someone out there!
New
snake117
I came across ElixirCasts.io, a free, high quality screencast showing various subjects in Elixir and Phoenix. I didn't see it posted on t...
New
ElixirCasts
I made an screencast that looks at Sobelow, a project that scans Phoenix applications for security issues. If you haven’t used Sobelow be...
New
Corys
I got a new video up on doing multi tenancy in phoenix 1.3 using Apartmentex. Lemme know if any questions. :grinning:
New
ryanwinchester
When: Sunday, July 19 @ 12PM Pacific Where: https://twitch.tv/ShyRyan Social: https://twitter.com/ryanrwinchester/status/12844417463786...
New
anuragg
One of our users just created this screencast for deploy Elixir apps on Render. Hope it’s helpful!
New
sevensidedmarble
New video dropped: this time on manually running your own asset build script with Bun. Bun is used as the script runner with ESBuild stil...
New
ElixirCasts
I made a screencast showing one way you can create SEO friendly urls with Phoenix 1.5.
New
aseigo
I am finally back with another episode of Exploring Elixir. Sorry for the long wait! My August was split between vacation and starting a ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
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
lanycrost
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

We're in Beta

About us Mission Statement