• Fat Cats Boardgame
  • Wicket UI Library
  • About Me

Java and Wicket web development thoughts, tutorials, and tips

roman@coderdreams.com
Coder DreamsCoder Dreams
  • Fat Cats Boardgame
  • Wicket UI Library
  • About Me

Pros and cons of unit testing

September 28, 2020 Posted by Roman Sery software design No Comments

You might be surprised that there are some downsides to unit testing. Not to worry, the pros still outweigh the cons in most cases, and we will examine that closer.

When I talk about unit testing, I don’t mean the type that is designed to manipulate a coverage tool to show a high percentage of coverage and not much else. That is possible and I have experienced pressure to do this when clients have a clause in their software contract about unit testing coverage levels.

The type of testing I’m talking about prioritizes creating tests aimed at trying to discover edge-case and other hard-to-reproduce bugs that might not be discovered just during normal QA and manual regression testing. Having a high percentage of coverage is still important, but the fact is, in any large system there exist large amounts of non-critical code where it’s not as important to thoroughly test them.

Pros

  1. Greater confidence in refactoring/implementing new features
    • The greatest fear for developers being assigned to work on new features/changes is introducing new bugs and breaking existing functionality.  This is especially true for the inexperienced or if you are just being introduced to a massive codebase.  Having an equally massive set of working and thoughtful unit tests gives you a lot of confidence in making changes and allows newer devs to get up to speed quicker.
  2. Possibility of discovering edge-case bugs
    • QA/acceptance testing is great and can uncover a lot of bugs, but there is some class of bugs that are very unlikely to occur during normal use.  Unit tests designed to test every edge-case, no matter how unlikely, can uncover these.  If your tests are really good, specifically designed, and are executed often, you even have a good chance of uncovering threading/concurrency issues.
  3. Remove the need for manual regression testing
    • This type of testing is usually a waste of time and unreliable.  The more unit tests you have, the more you can free up these resources to do other things like writing automated tests.

Cons

  1. A slower pace of development overall
    • Generally, when you need to implement new features or make significant changes to existing features, it can be done much faster without writing unit tests.  If it’s complex functionality, writing thoughtful and thorough tests can double or triple the development time.
  2. Slower and more difficult to do refactoring
    • When you have a large codebase including an equally large amount of unit tests, it’s going to make it more difficult and time-consuming to make changes.  In addition to changing all of the execution code, you have to change all of the associated tests.  It could just be to fix syntax errors, but usually, it would also involve changing tests completely as they may no longer make sense.
  3. Slower build times
    • Ideally, most of your tests will be very fast. But the reality you will have thousands of tests in a large real-world project, most of which need to execute DB transactions.  Even using an in-memory database, this will take up a lot of time when you build your project.  Probably leading to you turning off tests.

When to use unit testing

If you are working on a codebase that is mature with several clients, or even if you are on the cusp of getting your first clients and nearing a very stable set of features, you should use it. And if you have no unit testing, you should start as soon as possible.

It’s critical to start unit testing when having fewer bugs becomes more important than the speed of development. Or more specifically when the pros outweigh the cons.

The longer you put this off, the more likely it is that you will never have unit testing.

When to avoid it

If you are starting out with little or no code, you should by all means avoid it. Even if you have a lot of code, but are still trying to get your first clients and need to rapidly develop new features for demos/RFP’s and such, you should still avoid it. You will probably end up throwing out a lot, if not all of your code during a re-write anyway.

The problem is when you have ignored unit testing for many years and clients/management have gotten used to not dealing with the cons mentioned above, it’s very hard to make the switch. It’s hard to explain and justify the increased timelines to clients, especially when they have gotten used to a certain pace of development.

No Comments
Share
4

About Roman Sery

I've been a software developer for over 10 years and still loving Java!

You also might be interested in

Please dont use client-specific release branches

Aug 25, 2020

Why you should avoid a release strategy involving client-specific branches.

How to create dynamic HTML markup for Wicket panels

Nov 9, 2019

Use IMarkupResourceStreamProvider and IMarkupCacheKeyProvider to allow your Wicket Panel's to generate their own dynamic markup!

How to call Wicket code from JavaScript

Oct 23, 2019

How to call Wicket code from Javascript by adding a behavior to our WebPage and using it's callback URL.

Categories

  • aws
  • customization
  • database
  • debugging
  • enum
  • java
  • models
  • performance
  • projects
  • react
  • software design
  • Spring
  • tool
  • Uncategorized
  • wicket

Recent Posts

  • Rent Day
  • Self-contained Wicket Fragments
  • Pros and cons of unit testing
  • Themeable React Monopoly board
  • Please dont use client-specific release branches

Recent Comments

  • TCI Express Thanks for sharing such insightful information. TCI Express truly stands out as the best air logistics company, offering fast, secure, and efficient air express and cold chain transportation services....

    Tracking down a bug in production Wicket application ·  March 25, 2025

  • Tom Error: A zip file cannot include itself Can you please correct the plugin part so it doesn't use the same folder as input?

    Deploying Spring Boot app to AWS Beanstalk with Nginx customization ·  September 3, 2021

  • Golfman: Reality always wins I've used both Wicket and front-end JS frameworks and, having worked extensively on both, I can tell you that "Speed of development" is definitely NOT with the JS frameworks. You basically end up...

    Five reasons you should use Apache Wicket ·  August 29, 2021

  • Kiriller Sorry can not agree with you, wicket might be a well built technical framework. But the advantages of using a front-end framework like react.js and vue.js can not be beaten by Wicket nowadays. - Speed...

    Five reasons you should use Apache Wicket ·  August 23, 2021

  • Bernd Lauert Sorry but i have to refute your claims with the following arguments: 1. the Wicket community may be small but it is also very responsive, you usually get a helpful answer from the core devs on the...

    Five reasons you should use Apache Wicket ·  July 1, 2021

Archives

  • May 2021
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019

Contact Me

Send Message
Prev Next