About This Title

Pages: 262
Published: July 2021
ISBN: 9781680507829
In Print

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 $27.95 (USD)

Add to Cart we accept visa, mastercard, amex, discover, paypal


Paperback Formats:

Please support indie bookstores!
Find indie bookstores in the U.S. Find indie bookstores around the world.


Write Elixir tests that you can be proud of. Dive into Elixir’s test philosophy and conquer the 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:

  • P1.0 2021/07/27
  • B7.0 2021/06/22
  • B6.0 2021/04/30
  • B5.0 2021/03/18

Contents & Extracts

  • 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 Toward 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
    • Controlling the Life Cycle of OTP Processes in Tests
    • Testing Periodic Actions
    • Testing Singleton Resources
    • Testing Resiliency
    • Wrapping Up
  • 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 with Setup
    • Testing Create
    • Testing Read
    • Testing Update
    • Testing Delete
    • Wrapping Up
  • Testing Phoenix
    • The Role of Phoenix in Your Application
    • Testing JSON-Based APIs
    • Testing Server-Rendered HTML Applications
    • Testing Phoenix Channels
    • Wrapping Up
  • Property-Based Testing
    • Property-Based Testing in Practice in the Elixir Standard Library
    • 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
  • When To Randomize Test Data
  • Test Life Cycle
    • The Life Cycle of an ExUnit Suite
    • Test Cases
    • Executing Tests
    • An Example and a Drawing
  • Test Coverage
    • Built-In Test Coverage
    • Coveralls and the Excoveralls Library

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 $27.95 (USD)

Add to Cart we accept visa, mastercard, amex, discover, paypal


Paperback Formats:

Please support indie bookstores!
Find indie bookstores in the U.S. Find indie bookstores around the world.

Related Titles:

Skill Level Meter

About This Title

Pages: 262
Published: July 2021
ISBN: 9781680507829
Edition: 1
In Print