Beware the Person that Advises Against 100% Code Coverage Unit Testing (2024)

As a quality assurance specialist I was the customers advocate. As a malpractice attorney specializing in software, I am still the customer’s advocate but in a different arena and profession.”

--borrowing a turn of phrase from Susan A. Capra

People can follow and remember simple rules. Write unit tests to cover 100% of the lines of code that are written. So, simple. So, understandable. And, there are tools that will measure coverage for you. I will begin with some of the comical arguments against, and finish with the arguments for code coverage.

Arguments Against Unit Testing to Coverage

The first argument is we don’t have enough time. If you don’t have enough time to write tests, how are you going to have enough time to fix bugs? There are always bugs. If you don’t have enough time then either the schedule is wrong or too much technical debt (entropy) is being created. Without unit tests to code coverage, you can’t safely refactor. If you can’t refactor then you can’t mitigate entropy.

It isn’t possible to get 100% coverage with unit tests. If it is possible to write the code then its possible to test the code. If a test can’t be written then either the code is not understood or the code is not needed. There are testing tools for every layer of architecture.

UI/UX’s cannot be tested. There are a zillion tests libraries for testing client-side code: Jest, Mocha, Chai, QUnit, Vite, and so may other tools.

Integration tests are too expensive or time consuming. There are several mocking libraries like JustMock. You can also use backup and restore or scripts to stage your test database. Include a reset strategy for the back end. If you are using a service then mock the service.

Database testing isn’t supported. MS SQL Server has SSDT for database testing. You can also simply write coded database tests. With old UDB stored procedures were written in C, so writing coded database tests made sense.

Testing is for edge cases and functional behavior. 2Testing is for everything. It may be very difficult to guess the edge cases. The edge cases may never happen. When an edge case occurs you add a unit test for that, redesign the offending algorithm and it never happens again. Edge case closed.

If we change the behavior then we’ll have to re-write the tests. Precisely. If you change behavior the old tests may not cover anything. So, write the new tests and get back to coverage.

Recommended by LinkedIn

Mocks, Spies, and Stubs: How to Use? testRigor 1 month ago
Cut the Spaghetti Code Sollers Consulting 6 months ago
Jit Tech News 14 Jit Team 5 months ago

Sane Reasons to Test to Code Coverage

Put the brakes on trace bias testing. Without a simple, iron rule like testing to 100% code coverage the average programmer will test with a trace bias. Trace bias is designed to affirm what one wants to be true. With code coverage it is necessary to test the success and failure path.

Teaches programmers to write better code. The other thing code coverage testing does is it penalizes those writing “big balls of mud” and “spaghetti code”. It is very difficult to get to code coverage the code is horrible.

Encourages good metrics. If your metrics are horrible then testing is to coverage becomes very difficult. Metrics include cyclomatic complexity (branch statements), lines of code (a likely violation of the single responsibility principle (SRP)), maintenance complexity (overall measure of entropy) and computational complexity (algorithms with a nasty Big-O).

As a general rule you must have at least one test for every branch. Write a method with 15 branches and you’ll end up writing at least 15 tests for that function.

You’ll save money and preserve goodwill and customer affinity. If you don’t test to coverage, you’ll have a nasty surprise eventually. If you missed an edge case the discipline of coverage will close it quickly, let you run tests—thousands in minutes—and re-deploy with the knowledge that you haven’t cause multiple regression errors.

You’ll save money because you will have fewer bug fixes, fewer catastrophic failures, and bug fixes cost disproportionately higher than writing code.

To sum up: You want programmers to write code that follows things like SOLID principles. This requires a disciplined practice. Part of any disciplined practice is to test what you’ve written before doing a pull request. Part of any disciplined practice is the one that created the mess is responsible for cleaning it up.

Adding 100% code coverage to your practice means ultimately programmers will code better, create less technical debt, and projects will begin to come in ahead of schedule and under budget.

Paul Kimmel is a software architect who specializes in building teams and solid software and has delivered software on most of the computer platforms still in existence.

Beware the Person that Advises Against 100% Code Coverage Unit Testing (2024)
Top Articles
Sell Gift Card For Bitcoin
Staking vs Yield Farming vs Liquidity Mining- What's The Difference? [UPDATED] - Blockchain Council
Drury Inn & Suites Bowling Green
Bild Poster Ikea
Evil Dead Rise Showtimes Near Massena Movieplex
Linkvertise Bypass 2023
Call of Duty: NEXT Event Intel, How to Watch, and Tune In Rewards
Ree Marie Centerfold
6th gen chevy camaro forumCamaro ZL1 Z28 SS LT Camaro forums, news, blog, reviews, wallpapers, pricing – Camaro5.com
Worcester On Craigslist
Who called you from 6466062860 (+16466062860) ?
Burn Ban Map Oklahoma
Craigslist Malone New York
Q Management Inc
Spergo Net Worth 2022
Amih Stocktwits
Tinker Repo
Halo Worth Animal Jam
Healthier Homes | Coronavirus Protocol | Stanley Steemer - Stanley Steemer | The Steem Team
Adt Residential Sales Representative Salary
Sullivan County Image Mate
South Bend Weather Underground
Disputes over ESPN, Disney and DirecTV go to the heart of TV's existential problems
Il Speedtest Rcn Net
University Of Michigan Paging System
Used Patio Furniture - Craigslist
Bolsa Feels Bad For Sancho's Loss.
Walgreens On Bingle And Long Point
Viduthalai Movie Download
Worthington Industries Red Jacket
Albertville Memorial Funeral Home Obituaries
Nurofen 400mg Tabletten (24 stuks) | De Online Drogist
Rays Salary Cap
Salemhex ticket show3
Motor Mounts
Swgoh Boba Fett Counter
Space Marine 2 Error Code 4: Connection Lost [Solved]
Die Filmstarts-Kritik zu The Boogeyman
Hingham Police Scanner Wicked Local
The Closest Walmart From My Location
Karen Wilson Facebook
1Exquisitetaste
Craigslist Odessa Midland Texas
Bunkr Public Albums
ESA Science & Technology - The remarkable Red Rectangle: A stairway to heaven? [heic0408]
Blackwolf Run Pro Shop
Satucket Lectionary
Shell Gas Stations Prices
Go Nutrients Intestinal Edge Reviews
R/Gnv
Wood River, IL Homes for Sale & Real Estate
Die 10 wichtigsten Sehenswürdigkeiten in NYC, die Sie kennen sollten
Latest Posts
Article information

Author: Prof. An Powlowski

Last Updated:

Views: 6597

Rating: 4.3 / 5 (64 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Prof. An Powlowski

Birthday: 1992-09-29

Address: Apt. 994 8891 Orval Hill, Brittnyburgh, AZ 41023-0398

Phone: +26417467956738

Job: District Marketing Strategist

Hobby: Embroidery, Bodybuilding, Motor sports, Amateur radio, Wood carving, Whittling, Air sports

Introduction: My name is Prof. An Powlowski, I am a charming, helpful, attractive, good, graceful, thoughtful, vast person who loves writing and wants to share my knowledge and understanding with you.