Fundamentals 9 min read

Who Should Write Unit Tests? Weighing Developer vs Tester Pros & Cons

This article examines the debate over who should write unit tests—developers or testers—by outlining the advantages and disadvantages of each role, explaining what unit testing is, how to design effective test cases, and offering practical guidance for implementing high‑quality automated tests.

Programmer DD
Programmer DD
Programmer DD
Who Should Write Unit Tests? Weighing Developer vs Tester Pros & Cons

Many companies need unit testing, but who should actually write the tests varies across organizations.

Developer Writing Unit Tests

Advantages:

1. Developers are most familiar with the code and have strong coding skills, leading to higher efficiency and coverage when they write unit tests. 2. Unit testing sometimes requires code refactoring, which developers can perform more comfortably.

Disadvantages:

1. Developers are often busy with feature development and may lack time for unit testing. 2. Many developers lack solid testing mindset; their tests may be overly simple, passing while underlying functionality remains flawed.

Tester Writing Unit Tests

Advantages:

1. Testers typically possess better testing thinking, ensuring more comprehensive coverage. 2. Writing tests helps testers understand code structure and flow, benefiting subsequent business testing.

Disadvantages:

1. Skilled testers with strong coding ability are scarce, and they may need developers' help for refactoring to improve testability. 2. Efficiency is generally lower than when developers write the tests themselves.

What Is Unit Testing?

Unit testing is the practice of checking and verifying the smallest testable parts of software—usually functions or classes—in isolation from the rest of the program.

It is typically performed by developers, accompanies the code in the repository, and represents the most rigorous level of software testing, offering early, low‑cost quality assurance.

Because unit tests are automated, they provide high returns in large regression testing scenarios.

Additionally, writing unit tests can improve code design and serve as usage examples for the functions under test.

How to Do Unit Testing Effectively

To excel at unit testing, you must understand that the test target is the code itself, grasp its basic characteristics and common error sources, and master fundamental techniques such as driver code, stub code, and mock code.

Code Characteristics and Error Causes

Regardless of language, code consists of conditional branches, loops, and function calls, essentially performing data classification and processing. Missing, incorrect, or mishandled classifications lead to defects.

In practice, developers consider:

Normal input scenarios for correct functionality.

Special boundary inputs that need distinct handling.

Potential illegal inputs and their mitigation.

These categories correspond to the “equivalence classes” used in unit test design.

Unit Test Case Details

A unit test case consists of a set of "input data" and the "expected output". The input data can be more than just function parameters; it includes global/static variables, member variables, data returned from called sub‑functions, data modified by sub‑functions, and even data altered during interrupt handling in embedded systems.

Function input parameters

Global/static variables read by the function

Member variables accessed by the function

Data obtained from sub‑function calls

Data modified by sub‑function calls

Data changed during interrupt handling (embedded systems)

The author also analyzes the "expected output" categories, discussing driver code, stub code, and mock code, and their relationships (see illustration).

Driver, stub, and mock code relationship diagram
Driver, stub, and mock code relationship diagram

Understanding these concepts enables the creation of thorough, automated unit tests that improve code quality and reduce future maintenance costs.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Software Testingunit testingtest case designdevelopertester
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.