DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Key ML Classification Metrics You Need to Understand
  • Shift-Left Without Losing the Audit Trail: Test Automation for Regulated Surgical Software
  • Good Data, Bad Metric: A Mutation Testing Pattern for Analytics Engineering
  • Why AI Agents Are the New Backbone of Software Quality

Trending

  • OwlVigil Open-Sources Its Go SDK for Enterprise AI
  • Key ML Classification Metrics You Need to Understand
  • Choosing a BBD Framework
  • How (and Why) to Build Dynamic Data Pipelines

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Maintenance
  4. Code Churn — A Magical Metric for Software Quality

Code Churn — A Magical Metric for Software Quality

Learn about the code churn metric and how it helps pinpoint issues and protect software quality.

By 
Lokesh Raj
·
Dec. 03, 18 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
14.1K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

There are many ways of protecting the quality of the software and devising various techniques to ensure the right test plan for each software release. Based on my experience in many projects from small size to enterprise level, code churn-based analysis and testing are very effective in uncovering issues and protecting software quality. Code churn is nothing but code changes made for the software to achieve a certain functionality.

Code Churn

While designing test plans, the basic question to ask would be to find out what code changes are done in the software. There are multiple contexts to this; one is from the functional perspective and another from a code perspective.

The functional perspective would help to do black box testing. If you understand the functionality well and what has been changed in the current feature, then it would be easy to come up with an effective test plan to test the modified functionality.

However, in legacy or enterprise level software, it is not sufficient. The code written to change or add a functionality would have many side effects, like

  • Direct dependent code
  • Reused code
  • Business rules changing, especially various code paths

In such cases, black box testing would not be enough. It is important to know the code churn (changes).

What to Look for in Code Churn

Below are a couple of important takeaways we can derive from code churn:

  • Code churn size
  • Type of churn
  • Breadth of code churn
  • Depth of code churn

Let’s briefly understand them one by one.

Code Churn Size

In this metric, we mainly need to understand the number of lines changed to achieve the functionality. It will provide information like

  • If it's a completely new code (class, method).
  • Whether it requires unit-level tests to ensure it is tested for various inputs, output, and associated business rules.
  • What existing code was modified for specific (new or modified) business rules, data changes, etc.
  • The overall size of the code as a generic factor (e.g. for a story of size 5 point, are there 100 lines of code or few, etc.); it will give a sense of criticality of the change.

Types of Churn

This is mainly to understand the type of tests to include. Some of the important factors to understand are

  • Server-side change – Test cases required for application layer code and stored procedure changes.
    • Is it functional or non-functional?
  • Client-side change like HTML, JS, CSS, etc. — This will help us to put test cases related to UI responsiveness, multiple browser tests, accessibility tests, device tests, etc.

Breadth of Code Churn

It will help to identify a list of dependent functionalities and modules to be regressed. From a functional perspective, it might not be dependent on other modules, however, if the code is reused in other modules, then it may be required to consider them under regression tests.

If the code change is done in a utility function which is reused in multiple modules, it may be required to regress the dependent areas as well.

Depth of Code Churn

This will help testers to define what level of test cases are to be written. If the code is completely rewritten or changed on multiple levels, then unit-level, integration, and regression test cases are required. If it is just a specific area of code changed, then identify only the test cases specific to the area of the change.

Useful Tools

By looking at the above advantages of using code churn, it is easier said than done, unless we have the right tools to provide such useful information.

There are many tools we can use for such analysis, however, a few tools that we found to be very useful are listed below:

  • Git – code repository. We wrote a small tool that will connect to the git repository and pull the metrics for the given date period from the git repository range, like

    • List of files changed
    • Type of files changed based on file extensions like .vb, .cs, .js, .css, .html, etc.
    • Number of lines added
    • Number of lines modified
    • Total code churn
  • N-Cover — This is a comprehensive tool to identify code coverage. We will be able to identify how much of the code is tested through tests executed and any gaps in the testing. It adds more value to figure out the gaps in testing and filling those gaps immediately.

How to Use Code Churn Data

Effective use of code churn can be made in many ways.

  • The code churn report should be generated on a daily basis and should be used for BVT (Build, Verification, Test).
  • Code churn should be the basis for sprint tests so that each day of code is tested on a day-to-day basis.
  • The code churn report can be used for finalizing release-level test plans to identify the list of modules, components, and subcomponents to be regressed.
  • Code churn should be used during group technical reviews, as well, to understand the complexity, size, and dependency of code changes.

To summarize the benefits of code churn, it is like hitting the bull’s eye instead of executing test cases blindly based on merely functional aspects. Using a code churn-based test plan, it will test the exact code that is added/modified/deleted. This way, we will not be shooting in the dark.

Software Testing Software quality Metric (unit)

Opinions expressed by DZone contributors are their own.

Related

  • Key ML Classification Metrics You Need to Understand
  • Shift-Left Without Losing the Audit Trail: Test Automation for Regulated Surgical Software
  • Good Data, Bad Metric: A Mutation Testing Pattern for Analytics Engineering
  • Why AI Agents Are the New Backbone of Software Quality

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook