About This Title

Pages: 220
Published: December 2020
ISBN: 9781680507829
Edition: 1
In Beta

Skill Level Meter

Testing Elixir

Effective and Robust Testing for Elixir and its Ecosystem

by Andrea Leopardi and Jeffrey Matthias

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.

eBook Formats:

  • PDF for desktop/tablets

  • epub for Apple Books, e-readers

  • mobi for Kindle readers

Get all eBook formats here for $24.95

Add to Cart

This book is in Beta, final version expected Dec 2020

Beta Books: What do I get?


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.

What You Need

To get the most out of this book, you will need to have installed Elixir 1.8 or later and Erlang/OTP 21 or later. In order to complete the relevant chapters, you will also need Ecto 3.1 or later, EctoSQL 3.1 or later and Phoenix 1.3 or later.

Resources

Releases:

  • B3.0 2020/09/02
  • B2.0 2020/07/09
  • B1.0 2020/06/12

Contents & Extracts

Note: Contents and extracts of beta books will change as the book is developed.

  • Introduction
    • Why Do We Need a Book for Testing in Elixir?
    • Who This Book is For
    • How To Read This Book
    • About the Code
    • Online Resources
  • Unit Tests
    • Defining the Unit in Unit Test
    • Testing with ExUnit
    • Organizing Your Tests
    • Creating Comprehensive Test Coverage
    • Testing Pure Functions
    • Refactoring Towards Pure Functions
    • Isolating Code
    • Wrapping Up
  • Integration and End-to-end Tests
    • What Is an Integration Test?
    • Testing Against Real External Dependencies
    • Dependency Doubles
    • Interfacing to External Dependencies with Behaviours
    • Test Doubles: Stubs, Mocks, and Fakes
    • The Hidden Benefits of Dependency Doubles
    • Testing the Actual Interaction With Services excerpt
    • End-to-end Tests
    • Wrapping Up
  • Testing OTP
    • Testing a GenServer
    • Testing Periodic Actions
    • Testing Singleton Resources
    • Testing Resiliency
  • Testing Ecto Schemas
    • Testing Your Schema Through Changesets
    • Refactoring to Increase Test Maintainability
    • Creating a SchemaCase for Shared Test Code
    • Testing an Ecto Schema as a Data Validator
    • Testing an Ecto Schema for Database Interactions
    • Testing Your Schema Through Database Calls
    • Setting Up Sandbox Mode
    • Wrapping Up
  • Testing Ecto Queries
    • Creating a Factory to Help with Setup
    • Adding a DataCase to Help Setup
    • Testing Create
    • Testing Read
    • Testing update
    • Testing delete
    • Wrapping Up
  • Testing Phoenix
  • Property-based Testing
    • Example-based Tests excerpt
    • Introducing Randomness and Property-based Testing
    • Data Generation
    • Writing Properties
    • Shrinking
    • Strategies for Designing Properties
    • Stateful Property-based Testing
    • Wrapping Up
  • Deep Dive Into Testing With Mix
    • Running Tests

Author

Andrea Leopardi is a software developer and engineer with a passion for programming and code design. He loves beautiful and thoroughly tested code. He’s a member of the core team of the Elixir programming language. He’s also a frequent public speaker and trainer.

Jeffrey Matthias is a software engineer and industrial designer who loves modularity and quick feedback loops, two things that testing can help facilitate in code. When he’s not coding, he’s (helping his awesome wife with) raising his two kids and starting projects that he might finish someday.

eBook Formats:

  • PDF for desktop/tablets

  • epub for Apple Books, e-readers

  • mobi for Kindle readers

Get all eBook formats here for $24.95

Add to Cart

This book is in Beta, final version expected Dec 2020

Beta Books: What do I get?

Related Titles:

Skill Level Meter

About This Title

Pages: 220
Published: December 2020
ISBN: 9781680507829
Edition: 1
In Beta