Why Developers Say to Write Unit Tests, But Nobody Actually Does

Why Developers Say to Write Unit Tests, But Nobody Actually Does

Unit testing is a hot topic in software development. Everyone says it’s important, but in reality, many developers and companies choose to skip it. Why? Because time is money, and maintaining tests is often seen as an additional burden rather than a necessity. In this post, we’ll break down the realities of unit testing, when it’s crucial, and the myths surrounding it.

The Good and Bad of Unit Testing

The Good

  1. Catches Bugs Early: Tests help identify issues before they reach production.
  2. Refactoring Confidence: With tests in place, you can refactor code without fear of breaking things.
  3. Better Documentation: Tests can serve as documentation for how your code is supposed to behave.
  4. Crucial for Libraries and APIs: If your code will be used by others, having unit tests ensures reliability.

The Bad

  1. Maintenance Overhead: Tests need to be maintained along with the code, increasing the overall workload.
  2. False Sense of Security: 100% test coverage doesn’t mean bug-free code.
  3. Time and Cost: Writing and maintaining tests takes time, and many companies opt to skip them under deadline pressure.
  4. Over-testing is Real: Not every line of code needs a test, and excessive testing can lead to slower development.

Why Companies Skip Unit Testing

1. Budget Constraints

Writing tests takes time, and in many businesses, time is directly linked to money. Companies often prefer to allocate resources toward feature development rather than tests.

2. Pressure to Deliver

Management wants features shipped fast. In high-pressure environments, testing is often seen as an optional luxury rather than a necessity.

3. Short Product Lifespan

For MVPs or startups testing market fit, writing tests for code that may be rewritten or discarded in a few months is often seen as wasteful.

4. Lack of Proper Culture

Many teams never had a strong testing culture, leading to a ‘ship first, fix later’ mindset.

Common Myths About Unit Testing

1. No Tests Means Unprofessional Code

Not having tests doesn’t automatically mean bad code. Some well-structured and well-reviewed codebases function efficiently without extensive unit tests.

2. More Tests Mean Better Code

Writing more tests doesn’t improve code quality if the tests are poorly written or redundant. Good tests focus on critical paths and edge cases.

3. 100% Test Coverage Means No Bugs

You can have 100% test coverage and still have bugs, especially in areas not well-represented in test cases.

4. Tests Guarantee Bug-Free Code

Tests reduce the chance of bugs, but they don’t eliminate them. Real-world issues like incorrect logic, integration failures, and user behavior can still cause failures.

5. Tests Can Have Bugs Too

A faulty test can give a false positive, leading to misplaced confidence in the code. This is why test reviews are just as important as code reviews.

6. Tests Are an Investment, Not an Expense

Good tests save time in the long run, but bad or excessive tests can become tech debt, requiring extra maintenance.

When Are Unit Tests Crucial?

Not every piece of code needs unit tests. However, there are cases where they are absolutely necessary:

  1. Publishing an NPM Package: A library used by others must be well-tested to ensure reliability.
  2. UI Component Libraries: Writing a test for every single React component in a typical project may be overkill, but if you’re building a UI library like Material UI, tests are essential.
  3. Complex Logic: Features like authentication, payment processing, or algorithms benefit from strong test coverage.
  4. Breaking Down Code for Easier Testing: Writing small, modular functions makes it easier to write meaningful tests.
  5. Business Logic: Testing core business logic ensures correctness, especially when business rules change.

The Rise of AI-Generated Tests

With AI tools like GitHub Copilot generating unit tests, writing tests is becoming easier. However, blindly trusting AI-generated tests poses risks:

  1. Lack of Context: AI-generated tests might not fully understand business logic or edge cases.
  2. Security Risks: Using AI tools means sharing code with third-party services, which could pose data security issues.
  3. False Positives: AI-generated tests may not be as reliable as human-written ones, leading to incorrect confidence in failing or passing scenarios.

Conclusion: Knowing When and How to Test

You don’t need unit tests to prove you’re a good developer—you need to know when and how to use them effectively. While testing is important, it’s not a one-size-fits-all solution. Instead of blindly writing tests for everything, focus on testing critical logic, reusable components, and high-impact features. A balanced approach to testing leads to a healthier codebase without unnecessary maintenance overhead.

To view or add a comment, sign in

More articles by Carlos Santana Roldán

  • #13 - Roman to Integer - Leetcode

    🧩 Problem Statement You are given a string containing a Roman numeral, and your task is to convert it to an integer…

  • #12 - Integer to Roman - Leetcode

    Roman numerals are an ancient way of representing numbers using combinations of letters from the Latin alphabet: . Each…

  • #11 - Container With Most Water - Leetcode

    One of the most popular interview problems on LeetCode is “Container With Most Water.” It’s not only a great test of…

  • #10 - Regular Expression Matching - Leetcode

    🔍 Problem Overview The Regular Expression Matching problem (Leetcode #10) asks you to implement a simplified version…

  • #9 - Palindrome Number – LeetCode

    Checking whether a number is a palindrome is a classic coding interview question that tests your ability to think…

  • #8 - String to Integer (atoi) - Leetcode

    📘 Problem Summary Implement a function that converts a string to a 32-bit signed integer similar to the C/C++ function…

  • #7 - Reverse Integer - Leetcode

    📌 Problem Statement Given a signed 32-bit integer , return with its digits reversed. If reversing causes the value to…

  • #6 - Zigzag Conversion - Leetcode

    Zigzag Conversion is a popular coding problem that appears in technical interviews and algorithm challenges. In this…

  • #5 - Longest Palindromic Substring - Leetcode

    Finding the longest palindromic substring is a classic algorithm problem that often shows up in interviews. In this…

  • 🔍 Binary Search Explained Like You're 7

    Let’s face it, binary search sounds complicated, but once you understand the trick behind it, it’s actually pretty fun.…

    1 Comment

Insights from the community

Others also viewed

Explore topics