collegeimprovements

collegeimprovements

Testing Elixir (PragProg)

by @whatyouhide and @idlehands

Elixir offers new paradigms, and challenges you to test in unconventional ways. Start with ExUnit: almost everything you need to write tests covering all levels of detail, from unit to integration, but only if you know how to use it to the fullest—we’ll show you how. Explore testing Elixir-specific challenges such as OTP-based modules, asynchronous code, Ecto-based applications, and Phoenix applications. Explore new tools like Mox for mocks and StreamData for property-based testing. Armed with this knowledge, you can create test suites that add value to your production cycle and guard you from regressions.

Write Elixir tests that you can be proud of. Dive into Elixir’s test philosophy and gain mastery over the terminology and concepts that underlie good tests. Create and structure a comprehensive ExUnit test suite, starting from the basics, and build comprehensive test coverage that will provide safety for refactoring and confidence that your code performs as designed. Use tests to make your software more reliable and fault tolerant.

Explore the basic tool set provided by ExUnit and Mix to write and organize your test suite. Test code built around different OTP functionality. Isolate your code through dependency injection and by using Mox. Write comprehensive tests for Ecto projects, covering Ecto as a database tool as well as a standalone data validation tool. Test Phoenix channels from end to end, including authentication and joining topics. Write Phoenix controller tests and understand the concepts of integration testing in Elixir. Learn property-based testing with StreamData from the author who wrote the library.

Code with high confidence that you are getting the most out of your test suite, with the right tools that make testing your code a pleasure and a valuable part of your development cycle.

Don’t forget you can get 35% off the ebook with our Devtalk discount, use code ‘devtalk.com:023:

Most Liked

kokolegorille

kokolegorille

There is a new discount available now… devtalk.com

Update: it is not a link, it is the new discount code!

idlehands

idlehands

Author of Testing Elixir

That’s not what I am saying, sorry if there is confusion. We show several ways to isolate code and I specifically mentioned Mox, so if you want me to pick, I’d say we lean more towards London/Mockist but also don’t find value in forcing people to declare their style. Not every problem is the same and I don’t solve them all the same way.

There is plenty in the book about isolating code and you’re likely find that while our definition of a unit is intentionally vague (that section is about thinking about your unit and understanding the concept of a black box), our examples focus on small parts of an application, often just a single module.

As I mentioned, I have a feeling that you might pick up some useful stuff, but my sense is that you’re solid enough in your opinions that you either will know most of it and disagree with plenty.

We really did try to take a fairly neutral approach on a lot of things, though, so if you’re looking for “how do I test X?” you might be able to find answers.

idlehands

idlehands

Author of Testing Elixir

Sorry, I never actually answered your question. I personally would likely test the modules but have an endpoint test that also proved everything works all the way through (happy path) and at least one error case. A login endpoint is pretty straight forward but most of the endpoints I’ve ever written have plenty of branching possibilities below the hood. So, instead of writing outside tests to hit every one of those branches, I isolate that code using whatever is the correct tool and exercise the branching logic. Then, the endpoint test would be to make sure that all of the pieces connect.

As far as which tests I start with, it 100% depends on the scenario every time. Sometimes I start really low-level and sometimes I start on the endpoint. The only thing that I’m dogmatic about is that I write my tests first.

Where Next?

Popular in Books Top

AstonJ
By Simon St. Laurent If you’re new to Erlang, its functional style can seem difficult, but with help from this hands-on introduction, y...
New
PragmaticBookshelf
Isaak Tsalicoglou Built for the curious, this isn’t your average programming book—it’s nearly 500 pages of hands-on mentorship beyond cod...
New
peerreynders
by Elvio Vicosa @elviovicosa elvio Learning a new framework is hard As a seasoned Rails developer, you know Rails and its components...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
AstonJ
by Ben Marx, José Valim, Bruce Tate Bring Elixir into your company, with real-life strategies from the people who built Elixir and use i...
New
waseigo
by Isaak Tsalicoglou Why this book is being written A few years ago I got fed up with the menial manual labor I was engaged in in our f...
New
PragmaticBookshelf
Svilen Gospodinov edited by Jacquelyn Carter @jkcarter Learn different ways of writing concurrent code in Elixir and increase your appli...
New
tristan
Adopting Erlang is a collaborative effort between myself (Tristan), Fred Hebert and Evan Vigil-McClanahan. It is an ongoing effort to gat...
New
peerreynders
Don’t forget you can get 35% off the ebook with your forum discount, use code ‘devtalk.com’ :023: Available in beta now
New
peerreynders
Don’t forget you can get 35% off the ebook using the code ‘devtalk.com’ :023: This title will be available on or about 2018-11-10
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
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...
3271 127536 1222
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

We're in Beta

About us Mission Statement