Single Responsibility Principle (SRP)

Single Responsibility Principle (SRP) image
Single Responsibility Principle (SRP) is a design principle stating that a class or function should have only one job or reason to change. When each unit of code does exactly one thing, it becomes much easier to understand, modify, and test in isolation. 

It has a direct connection to testability: clear, focused responsibilities make it straightforward to write and maintain tests because failures point to a single, well-defined concern rather than a tangle of mixed logic. 

SRP is one of the SOLID principles and closely related to DRY.

For example, a function that both fetches data and formats it for display violates SRP; splitting these into two functions makes each independently testable.
Explore MoT
AI-driven testing in practice: from requirements to reliable automation image
See where AI genuinely helps, where it doesn’t, and how testers can stay firmly in control
MoT Software Testing Essentials Certificate image
Boost your career in software testing with the MoT Software Testing Essentials Certificate. Learn essential skills, from basic testing techniques to advanced risk analysis, crafted by industry experts.
This Week in Quality image
Debrief the week in Quality via a community radio show hosted by Simon Tomes and members of the community
Subscribe to our newsletter