Following is a quick way to identify code with low testability and hence low maintainability:

  • Take any specific public method of the class
  • Count for number of decision points such as following:

– If
– For
– While
– Switch
– Inline ifs

  • If the number of decision points in a method is more than 15 or so, it could be taken as indication that it may get difficult to write unit tests covering all possible flows. Thus, the code will have lower testability.

The number of decision points in a method is also used to define/measure cyclomatic complexity of the method, or more specifically, McCabe Cyclomatic Complexity. Thus, mathematically speaking, testability can be represented as following:

Testability, T of a method is inversely proportional to No. of Decision Points, D, found in the method.

Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning and BI. I would love to connect with you on Linkedin. Check out my books titled as Designing Decisions, and First Principles Thinking.

Recent Posts

The Watermelon Effect: When Green Metrics Lie

We’ve all been in that meeting. The dashboard on the boardroom screen is a sea…

18 hours ago

Coefficient of Variation in Regression Modelling: Example

When building a regression model or performing regression analysis to predict a target variable, understanding…

3 months ago

Chunking Strategies for RAG with Examples

If you've built a "Naive" RAG pipeline, you've probably hit a wall. You've indexed your…

3 months ago

RAG Pipeline: 6 Steps for Creating Naive RAG App

If you're starting with large language models, you must have heard of RAG (Retrieval-Augmented Generation).…

3 months ago

Python: List Comprehension Explained with Examples

If you've spent any time with Python, you've likely heard the term "Pythonic." It refers…

3 months ago

Large Language Models (LLMs): Four Critical Modeling Stages

Large language models (LLMs) have fundamentally transformed our digital landscape, powering everything from chatbots and…

6 months ago