Skip to content
DevMeme
3895 of 7435
The Code-to-Test Ratio Iceberg
Testing Post #4241, on Feb 22, 2022 in TG

The Code-to-Test Ratio Iceberg

Description

A two-panel comic by '@THEJENKINSCOMIC' that visually contrasts production code with its corresponding tests. The left panel, labeled 'ACTUAL CODE,' shows a stylized code editor with only a few lines of colorful, abstract code at the very top, leaving the rest of the file empty. This represents a concise and simple piece of logic. In stark contrast, the right panel, labeled 'UNIT TESTS,' depicts an editor completely filled with lines of code, represented by alternating white and orange bars, signifying a massive amount of test code. The humor lies in this dramatic and relatable disparity. It accurately portrays the reality in robust, well-engineered systems where the volume of code required to set up mocks, define test cases, cover edge cases, and make assertions far exceeds the volume of the actual implementation code it's validating

Comments

9
Anonymous ★ Top Pick The function is one line, but the unit tests require mocking the entire Gregorian calendar and the concept of leap years just to validate a date formatting utility
  1. Anonymous ★ Top Pick

    The function is one line, but the unit tests require mocking the entire Gregorian calendar and the concept of leap years just to validate a date formatting utility

  2. Anonymous

    When your 30-line service has 3,000 lines of tests, you’re not shipping code - you’re shipping a compliance document with an executable appendix

  3. Anonymous

    The real achievement isn't 100% code coverage, it's convincing management that maintaining 3000 lines of mocks for a 50-line service is "technical debt reduction."

  4. Anonymous

    The code took an afternoon; the tests took a sprint - and the only bug shipped was in the mock

  5. Anonymous

    Ah yes, the classic 10:1 test-to-code ratio - where you spend three sprints writing comprehensive unit tests for a function that literally just returns true. Senior engineers know this pain intimately: you've got 50 lines of elegant, battle-tested production code, but 800 lines of test setup mocking dependencies, stubbing services, and asserting edge cases that'll never happen in production. The real kicker? When requirements change, you refactor 10 lines of actual code but spend two days updating 47 broken tests. It's the architectural equivalent of building a nuclear bunker to protect a garden shed - technically correct, but somewhere along the way we forgot to ask if we should

  6. Anonymous

    We hit 99% coverage by unit-testing the mocks that test the mocks - the feature is a thin adapter

  7. Anonymous

    Code: 12 lines. Tests: 1,200. 95% coverage, 0% confidence - every refactor breaks 600 mocks because they were the real API all along

  8. Anonymous

    Actual code: haiku. Unit tests: War and Peace - complete with every edge case subplot

  9. @CcxCZ 4y

    https://hypothesis.works/

Use J and K for navigation