Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 60587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:11:07+00:00 2026-05-10T18:11:07+00:00

What Makes a Good Unit Test? says that a test should test only one

  • 0

What Makes a Good Unit Test? says that a test should test only one thing. What is the benefit from that?

Wouldn’t it be better to write a bit bigger tests that test bigger block of code? Investigating a test failure is anyway hard and I don’t see help to it from smaller tests.

Edit: The word unit is not that important. Let’s say I consider the unit a bit bigger. That is not the issue here. The real question is why make a test or more for all methods as few tests that cover many methods is simpler.

An example: A list class. Why should I make separate tests for addition and removal? A one test that first adds then removes sounds simpler.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:11:08+00:00Added an answer on May 10, 2026 at 6:11 pm

    I’m going to go out on a limb here, and say that the ‘only test one thing’ advice isn’t as actually helpful as it’s sometimes made out to be.

    Sometimes tests take a certain amount of setting up. Sometimes they may even take a certain amount of time to set up (in the real world). Often you can test two actions in one go.

    Pro: only have all that setup occur once. Your tests after the first action will prove that the world is how you expect it to be before the second action. Less code, faster test run.

    Con: if either action fails, you’ll get the same result: the same test will fail. You’ll have less information about where the problem is than if you only had a single action in each of two tests.

    In reality, I find that the ‘con’ here isn’t much of a problem. The stack trace often narrows things down very quickly, and I’m going to make sure I fix the code anyway.

    A slightly different ‘con’ here is that it breaks the ‘write a new test, make it pass, refactor’ cycle. I view that as an ideal cycle, but one which doesn’t always mirror reality. Sometimes it’s simply more pragmatic to add an extra action and check (or possibly just another check to an existing action) in a current test than to create a new one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Ruby's test/unit, and other such nunit style frameworks, what makes a good failure
I like to get inspiration from using web applications that make good use of
Assume I want to write a unit test to test a particular piece of
I am wondering if unit testing private methods is a good practice? Normally only
Is there any good way to unit test destructors? Like say I have a
Exact duplicate of many posts: What is unit testing? What Makes a Good Unit
What properties of LLVM makes it good choice for implementation of (parallel, concurrent, distributed)-oriented
Kindly point towards theory/material to read for understanding colors and what makes a good
Any good reason why $(p).html(0) makes all paragraphs empty as opposed to contain the
I come from a mainly PHP background and make good use of the Apache

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.