Using automated unit tests to differentiate your code

My personal experience with writing white box automated unit tests covers most of the below benefits. Needless to say, I can't get enough of them :)

  • Repeated and quick execution (the more frequent you run them, the faster your feedback loop). Helps in early detection (and fixing) of bugs
  • No fear of code merge issues
  • No last minute surprises
  • Real regression...not smoke. Assumption is that you have more than 80% test code coverage for all key classes
  • Less dependence on specific people as it is easier to see programmer intent by studying the tests along with the code. Serves as technical documentation for your code
  • Higher quality as most often the source of bugs is unreadable or complex code. Unit tests allow you to refactor safely and quickly, hence keeping code readable and organized
  • Best way to prepare to pay off technical debt
  • Motivational! Programmers feel happy about their workday due to passing tests … hey, at-least something is working!! Its like gamification of programming
  • Automatically document the design / architecture
  • Quick debugging (studies show that 80% time is spent in locating the bug), if you have good unit tests you use the debugger less because your tests help you identify possible problems with your recently written code
  • If you use tests as technical documentation, then you don't have to worry about keeping your documentation current. Needless to say that good tests (with good test naming) work better than bad tests
  • Very effective if you follow the 80-20 rule. Choose carefully what you want to unit test first (in a code base that was not test driven from the start)
  • If you want stability (less bugs), then write tests for those modules which are the source of most recent bugs. In fact it is very desirable that you first reproduce the bug through the unit test and then fix the bug. This will ensure that the particular bug never comes again as their will be unit test in place to check for it every time. Remember, your client's confidence is shaken every time a bug reopens.
  • If you want higher productivity, then write tests for those modules which have more frequent code changes/commits
  • It promotes good design and separation of concerns
  • It improves quality and reduces bugs
  • It speeds the overall development process as you can quickly experiment and then run your tests every 15-30 minutes. If a lot of tests start to fail unexpectedly, you might choose to just rollback the work done in last 30 minutes and start fresh
  • Helps developer get out of coder’s block (just like writer’s block), allows you to safely experiment and poke around the problem
  • Helps you stay away from forking your code. You can quickly expand your feature set and not worry about manual regression testing for the new client. Usually people fork their code when they have to ship for a new client and don't have the time to build those new client specific features and test on the whole application.

Best way to start with unit test writing is to follow James Shore's famous YouTube series: https://www.youtube.com/watch?v=F534zh9rsaA

Muhammad Saif ul haq, thank you for highlighting this point that unit tests help you keep the critical code smells and technical debt below a threshold. If the company is being acquired, often the purchaser checks the technical debt and if you have a healthy and clean codebase then you can get a much more attractive price!!

Thinking more, unit tests (when using Karma tool) also help frontend developers in testing the code in the document object model (DOM) of multiple browsers. It is very powerful as you save time by avoiding triggering the tests one by one for each browser.

Like
Reply

Just want to share that I was doing a one to one with a developer recently, he shared with me that unit tests help him understand other people's code faster/better as he reads them along with the actual code to see the programmer intention. It confirms our stance that unit tests can serve as technical specifications if they are written and named well :)

To view or add a comment, sign in

More articles by Ansar Muhammad, Azure AI, PMP, PSM 1

  • AI Startup ideas for fresh computer science graduates

    Was discussing with some friends recently about this topic and here is what we came up with in no order of priority 1…

    1 Comment
  • Some Advantages of Small Language Models (SLMs)

    When you use tools like ChatGPT, we are engaging with large language models like GPT-5 behind the scene. These are good…

    1 Comment
  • AI Awards - Oct to Dec 2025

    Sharing a great milestone that reflects the incredible work our teams have been doing with AI! We recently hosted our…

    6 Comments
  • How to regularly test your Generative AI projects using Automated Evaluations

    When developing AI applications like Chatbot/RAG, etc. ensuring the accuracy and relevance of retrieved context is…

  • AI-Proof Programming Problem

    For some time I have been trying to come up with some programming problems that can't be solved by ChatGPT and others…

    5 Comments
  • Thought of the day!!

    In near future when people will apply for jobs, they will list their online agents that will come with them when they…

  • Generating Code from Tests

    While we agree that specification driven development is currently the best way to generate code using AI. We also want…

    1 Comment
  • Protecting your AI agents from Prompt Injection Attacks

    Some of you might be familiar with the OWASP top 10 for GenAI and LLMs. Prompt injection attacks are the highest rated…

  • A Prompt Fit for an Agent (Microsoft Copilot)

    The demo shows the value of a good prompt, even when all it does is take raw meeting notes and generate a structured…

  • Using Microsoft Copilot to find any errors in your Excel calculations

    There are times when you are working on a complex spreadsheet and you inadvertently add some calculation errors. AI…

    1 Comment

Others also viewed

Explore content categories