The Bike Shed

438: Writing abstractions in tests


Listen Later

Writing abstractions in tests can be surprisingly similar to storytelling. The most masterful stories are those where the author has stripped away all of the extra information, and given you just enough knowledge to be immersed and aware of what is going on. But striking that balance can be tricky, both in storytelling and abstractions in tests. Too much information and you risk overwhelming the reader. Too little and they won’t understand why things are operating the way they are. Today, Stephanie and Joël get into some of the more controversial practices around testing, why people use them, and how to strike the right balance with your information. They discuss the most common motivations for introducing abstractions, from improved readability to simplifying the test’s purpose and the types of tests where they are most likely to introduce abstractions. Our hosts also reflect on how they feel about different abstractions in tests – like custom matchers and shared examples – outlining when they reach for them, and the tradeoffs and benefits that come with each. To learn more about how to find the perfect level of abstraction, be sure to tune in!

Key Points From This Episode:

What’s new in Joël’s world; mocking out screens for processes or a new bit of UI.

The new tool Stephanie’s using for reading on the web: Reader by Readwise.
Today’s topic: controversial practices around testing.
How Stephanie and Joël feel about looping through arrays and having IT blocks for each.
The most common motivations for introducing abstractions or helper methods into your tests.
Pros and cons of factories as abstractions in testing.
Types of tests where Joël and Stephanie are more likely to introduce abstractions.
Using page objects in system tests to improve user experience.
Finding the balance between too little and too much information with abstraction in testing.
Why Stephanie has been enjoying fancier matchers like RSpecs.
Top uses of custom matchers, especially for specialized error messaging.
Why Stephanie prefers custom matchers over shared examples.
Using helper methods as a lighter version of abstraction.
Differences and similarities between abstractions in tests versus application code.
A reminder to keep your goals in mind when using abstraction.

Links Mentioned in Today’s Episode:

  • Reader by Readwise
  • Why factories
  • Why not factories
  • Capybara at a single level of abstraction
  • Writing custom RSpec matchers
  • Value objects shared examples
  • 'DRY is about knowledge'
  • Joël Quenneville on LinkedIn
  • Support The Bike Shed

    ...more
    View all episodesView all episodes
    Download on the App Store

    The Bike ShedBy thoughtbot

    • 4.9
    • 4.9
    • 4.9
    • 4.9
    • 4.9

    4.9

    121 ratings


    More shows like The Bike Shed

    View all
    Radiolab by WNYC Studios

    Radiolab

    43,815 Listeners

    Planet Money by NPR

    Planet Money

    30,681 Listeners

    Marketplace by Marketplace

    Marketplace

    8,762 Listeners

    Tentative by thoughtbot

    Tentative

    9 Listeners

    The Changelog: Software Development, Open Source by Changelog Media

    The Changelog: Software Development, Open Source

    289 Listeners

    Giant Robots Smashing Into Other Giant Robots by thoughtbot

    Giant Robots Smashing Into Other Giant Robots

    88 Listeners

    Build Phase by thoughtbot

    Build Phase

    44 Listeners

    Ruby Rogues by Charles M Wood

    Ruby Rogues

    45 Listeners

    Software Engineering Daily by Software Engineering Daily

    Software Engineering Daily

    625 Listeners

    Soft Skills Engineering by Jamison Dance and Dave Smith

    Soft Skills Engineering

    289 Listeners

    Syntax - Tasty Web Development Treats by Wes Bos & Scott Tolinski - Full Stack JavaScript Web Developers

    Syntax - Tasty Web Development Treats

    987 Listeners

    REWORK by 37signals

    REWORK

    210 Listeners

    Crossroads by thoughtbot

    Crossroads

    2 Listeners

    Remote Ruby by Chris Oliver, Andrew Mason

    Remote Ruby

    34 Listeners

    Reboot by thoughtbot

    Reboot

    12 Listeners

    Hard Fork by The New York Times

    Hard Fork

    5,507 Listeners

    Shell Game by iHeartPodcasts and Kaleidoscope

    Shell Game

    897 Listeners

    Complex Systems with Patrick McKenzie (patio11) by Patrick McKenzie

    Complex Systems with Patrick McKenzie (patio11)

    134 Listeners

    The Pragmatic Engineer by Gergely Orosz

    The Pragmatic Engineer

    64 Listeners

    Rails Business by Brendan Buckingham & Ryan Frisch

    Rails Business

    0 Listeners