Share E-Book

The Power of Go Tests (John Arundel) (Z-Library)

Author John Arundel

Go
Language English

No Description

Format EPUB
Size 3.3 MB
252
Views
0
Downloads
0.00
Total Donations

AI Guide

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

Full assistant
AI guide
# The Power of Go Tests — Reading Guide ## 【One-Line Pitch】 A practical, hands-on guide to writing effective tests in Go that will transform how you think about software design, correctness, and confidence in your code. Perfect for Go developers who want to move beyond basic testing and learn professional-grade testing techniques. ## 【Book Arc】 - **Opening (~0%–10%)**: Introduces the philosophy of test-driven development and why "self-testing code" is the foundation of confident programming. Sets up the core workflow: write tests first, watch them fail, then implement code to make them pass. - **Early (~10%–32%)**: Walks through a complete test-first example (building a `ListItems` function for a text adventure game), demonstrating the full cycle: writing a failing test, implementing minimal code, using `cmp.Diff` for better failure messages, and iterating. - **Middle (~32%–52%)**: Covers the "new behaviour, new test" rule, refactoring tests into table-driven tests, and systematically adding test cases one at a time. Emphasizes that tests are living documentation of intended behavior. - **Middle (~52%–70%)**: Explores advanced testing topics including error handling patterns, constructing effective test inputs, property-based testing, and fuzz testing to find edge cases you didn't anticipate. - **Late (~70%–90%)**: Introduces mutation testing to evaluate test quality, coverage analysis (as a signal, not a target), and techniques for testing "untestable" code like concurrency, CLI tools, and long-running tasks. - **Ending (~90%–100%)**: Presents `testscript` for testing command-line interfaces and end-to-end program behavior, wrapping up with the philosophy that tests are communication tools for future developers. ## 【Key Takeaways】 - **Tests-first development forces clarity** (Early): Writing tests before implementation compels you to define function names, signatures, and expected behavior upfront—the hardest design decisions—before writing any code. This prevents vague thinking and wasted effort. - **A test isn't real until you've seen it fail** (Early): The author emphasizes verifying that your test actually catches bugs by deliberately writing incorrect implementations first. If the test passes when it shouldn't, the test itself has problems. - **"New behaviour, new test" is a discipline** (Middle): Every time you think of new functionality, you must write a test for it first. This rule prevents scope creep and ensures you always know when you've written enough code. - **Table tests scale your coverage elegantly** (Middle): Structuring tests as tables of input/expected-output pairs lets you add cases one at a time, treating each as a distinct behavior to verify. This makes tests readable and maintainable. - **Error handling is part of your API** (Middle): How your code handles errors—whether it ignores them, wraps them, or uses sentinel errors—is a design decision that should be tested deliberately. Use `errors.Is` and `errors.As` for robust error checking. - **Fuzzing finds bugs you didn't know existed** (Middle–Late): Random input generation and property-based testing can uncover edge cases and panics that hand-written tests miss. Failing fuzz inputs should become permanent static test cases. - **Mutation testing reveals test quality** (Late): Deliberately introducing bugs ("mutants") into your code and checking whether tests catch them exposes weak tests and untested code paths. Coverage percentage alone is misleading. - **Tests are communication with future developers** (Throughout): Well-named tests read as documentation, capturing intent and serving as executable specifications. Test names should be sentences describing behavior, not implementation details. ## 【Reading Tips】 - **Deep-read Chapters 1–3** (the test-first workflow and test design philosophy): These chapters establish the mental model that everything else builds on. The `ListItems` example is worth following along with in your own editor. - **Skim the praise and introduction** (~0–10%): The motivational content is nice but not essential. Jump straight to the first chapter's practical content. - **Pay special attention to the "new behaviour, new test" section** (~42%): This is where the author addresses a common stumbling block for experienced programmers who are used to just writing code. - **The fuzzing and mutation testing chapters** (~70–90%) are the most advanced material: If you're new to testing, consider reading these twice or returning after practicing the earlier techniques. - **Try the exercises as you go**: The book is structured around building a text adventure game, so coding along with the examples will cement the concepts far better than passive reading. ## 【Coverage Limits】 This guide covers the book's progression from test-first fundamentals through advanced techniques like fuzzing and mutation testing, but the excerpts don't include the full details of the `testscript` chapter or the complete code listings for every example. ##

Passage locations

Excerpt 1
information Custom error types and errors.As Conclusions 5. Users shouldn’t do that Constructing effective test inputs User testing Crafting bespoke bug dete...
View in text
Excerpt 2
a clear idea of what it should do is simply a waste of time. It’s almost bound to be wrong in important ways. We’re also likely to end up with a design which...
View in text
Excerpt 3
ith some different error, we would know there was a problem. But it seems to be fine, so now we can go ahead and implement ListItems for real. Here’s one rou...
View in text
Excerpt 4
to insert an extra step in the process: writing a new test . Even when they’ve written a function test-first to start with, the temptation is then to start e...
View in text

Recommended for You

Loading recommended books...
Failed to load, please try again later

Tip the Site

Scan the WeChat Pay or Alipay code to tip. No login required.

WeChat Pay
Alipay
Back to List