← Latest papers
💻 computer science

Test Behaviors, Not Methods! Detecting Tests Obsessed by Methods

This paper proposes a novel test smell called "Test Obsessed by Method," which identifies tests that cover multiple execution paths of a single production method, and validates its detection through an empirical study on the Python Standard Library showing that such tests often verify multiple behaviors and can be refactored into more focused units.

Original authors: Andre Hora, Andy Zaidman

Published 2026-02-03
📖 4 min read☕ Coffee break read

Original authors: Andre Hora, Andy Zaidman

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are a chef preparing a tasting menu for a food critic. The golden rule of great cooking is: serve one distinct flavor per dish. If you serve a single plate containing a steak, a slice of cake, and a scoop of ice cream all mixed together, the critic gets confused. They can't tell if the steak is undercooked, the cake is too sweet, or the ice cream is melting. If something goes wrong, they don't know which part of the meal to blame.

In the world of software, "dishes" are tests, and "flavors" are behaviors (what the software is supposed to do).

This paper, titled "Test Behaviors, Not Methods!", argues that many software tests are currently being served like that messy mixed plate. The authors, Andre Hora and Andy Zaidman, introduce a new way to spot these confusing tests, which they call "Tests Obsessed by Methods."

Here is the breakdown of their discovery using simple analogies:

1. The Old Way: Counting the Ingredients

Previously, experts tried to find these messy tests by simply counting how many times a test "touched" the code. They thought, "If a test calls the production code 3 or more times, it's probably doing too much."

The authors call this the "Eager Test" smell. However, they found this method is like judging a meal just by counting how many spoons were used. It's inaccurate. A test might call a function many times just to set up a scene, without actually testing different flavors. It's a clumsy way to find the problem.

2. The New Idea: Watching the Movie (Runtime Analysis)

Instead of just counting spoonfuls, the authors suggest watching the movie of the test as it plays out. They propose a new rule: If a single test forces a piece of code to take multiple different "roads" (paths) to get to the finish line, that test is "obsessed."

Think of a production method (a piece of code) as a maze.

  • Good Test: You send one explorer into the maze to check if the left door works. Then you send a second explorer to check if the right door works. Clear and focused.
  • Obsessed Test: You send one explorer who runs through the left door, then backtracks, runs through the right door, and then tries the secret tunnel, all in one go.

The authors call this "Test Obsessed by Method." The test is "greedy" because it tries to cover every possible path of a single maze in one go, rather than splitting the job up.

3. The Experiment: Checking the Python Library

To see if this "obsession" is a real problem, the authors went on a scavenger hunt through the Python Standard Library (a massive collection of pre-written code used by millions of developers).

They looked at 2,054 tests. Here is what they found:

  • The Hunt: They found 44 tests that were "obsessed." These tests were trying to check multiple different outcomes of a single function in one go.
  • The Spread: These messy tests were found in 11 out of 12 different libraries they checked. It's not a rare glitch; it's a common habit.
  • The Fix: On average, each of these 44 messy tests was actually trying to do two different jobs. If you split them up, those 44 tests could become 118 clean, focused tests.
  • The "Aha!" Moment: In about 23% of these messy tests, the programmers had actually written comments admitting, "Hey, we are testing two different things here!" They knew it was messy but did it anyway.

4. Why Does This Matter?

The authors argue that when a test tries to cover too many paths at once:

  • It's hard to understand: Like that mixed plate, you can't tell what flavor you're tasting.
  • It's fragile: If you change the code for the "left door," you might accidentally break the test for the "right door," even though they are unrelated.
  • It's hard to fix: When a test fails, you don't know which specific behavior broke.

The Bottom Line

The paper doesn't claim to solve every testing problem. Instead, it offers a new, sharper tool (using runtime analysis instead of just counting) to spot tests that are trying to do too much with a single piece of code.

They suggest that if a test forces a function to take multiple different paths, it should be split up. Just like a chef should serve the steak, the cake, and the ice cream on separate plates, a developer should write separate tests for every distinct behavior.

In short: Don't be greedy with your tests. Test one behavior, one path, one flavor at a time.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →