High-Quality Code- Naming Methods

High-Quality Code- Naming Methods

In the last articles from the High-Quality Automated Tests we talked about coding styles and various tools that can help you to force them automatically. In this publication, I am going to talk about different methods naming guidelines your tests should follow so that they are more readable and maintainable by other people.

While ago when we were working on the first version of the BELLATRIX test automation framework, I did this research while I was working on a similar feature for our solution.

Naming Methods

Method names should answer the question- What does this method do? If you cannot find a good name for a method, think about whether it has a clear intent. Because methods are the means of taking action, the design guidelines require that method names be verbs or verb phrases.

Correct

FindStudent, LoadReport, PlaceOrder, CreatePurchase

Incorrect

Method1, DoSomething, HandleStuff, SampleMethod, DirtyHack

Use PascalCase for C#. For example LoadSettings. Prefer the following formats [Verb], [Verb] + [Noun],[Verb] + [Adjective] + [Noun].

Correct

Generate, LoadSettingsFile, FindNodeByPattern, ToString, PrintClientsList

Incorrect

Student, Generator, Counter, White, Approximation, MathUtils

Do Not Use Underscores in Method Names

Life cycle events are exception.

Correct

public SendActionKeys(IKeyboard keyboard, IMouse mouse, ILocatable actionTarget, string keysToSend)
{
    //...
}

Incorrect

public Send_Action_Keys(IKeyboard keyboard, IMouse mouse, ILocatable actionTarget, string keysToSend)
{
    //...
}

Meaningful Method Names

Correct

int count = GetCountByStampId(Tenant tennat, long stampId);

Incorrect

// get objects count filtered by stampId
int count = GetAllByStampCount(Tenant tennat, long stampId);

Correct

var meanDemand = CalculateMeanDemand();

Incorrect

// calculate mean demand
double meanDemand = Calculate();

Do Not Use Many Method Parameters

Correct

protected virtual DependentDemandValue InitDe-pendentDemand(
DateTime startDate,
DateTime endDate,
int counter,
int futureCounter,
bool isForDailyBucket)
{
    //..
}

Incorrect

protected virtual void InitDependentDemand(
DateTime startDate,
DateTime endDate,
int counter,
int futureCounter,
bool isForDailyBucket,
out double dependentDemand,
out double dependentDemandFirm,
out double futureDependentDemand,
out double upperLevelForecast,
out double dependantDemandWithoutDestinationSO)
{
    // ...
}

The Length of Method Names

How long could be the name of a method? The name should be as long as required. Do not abbreviate. Use your IDE’s autocomplete.

Correct

LoadCustomerSupportNotificationService, CreateMonthlyAndAnnualIncomesReport

Incorrect

LoadCustSuppSrvc, CreateMonthIncReport

Naming Method Parameters

Method parameters names preferred form: [Noun] or [Adjective] + [Noun]. Should be in camelCase. Should be meaningful. Unit of measure should be obvious.

Correct

firstName, report, supportTicket, recurringBillingOrder, sku

Incorrect

p, p1, p2, populate, LastName, last_name, convertImage

Single Purpose of All Methods

Methods should have a single purpose! Otherwise they cannot be named well. Methods that have multiple purposes (weak cohesion) are hard to be named. They need to be refactored instead of named. 

Consistency in Methods Naming

Use consistent naming in the entire project. LoadFile, LoadImageFromFile, LoadSettings, LoadFont, LoadLibrary, but not ReadTextFile.

Use consistently the opposites at the same level of abstraction.

  • LoadLibrary vs UnloadLibrary, but NOT FreeHandle
  • OpenFile vs CloseFile, but NOT DeallocateResource
  • GetName vs SetName, but NOT AssignName

Summary

In the second part of the naming guidelines series of articles we looked at various rules about naming methods which can make your tests much more readable and maintainable. In the next publications, we will go through a list of practices for naming properties and variables.

Related Articles

High-Quality Automated Tests

High-Quality Code- Naming Classes, Interfaces, Enumerations

In the last articles from the High-Quality Automated Tests we talked about coding styles and various tools that can help you to force them automatically. In thi

High-Quality Code- Naming Classes, Interfaces, Enumerations

High-Quality Automated Tests

High-Quality Automated Tests- Top 10 EditorConfig Coding Styles Part 1

This is the second article from the new series- High-Quality Automated Tests. In the previous publication, I showed you how to apply coding standards and styles

High-Quality Automated Tests- Top 10 EditorConfig Coding Styles Part 1

High-Quality Automated Tests

Testing for Developers- Isolation Frameworks Fundamentals

In the series we will define the basic terms that every developer needs to know about testing. The purpose is to give all team members a shared understanding of

Testing for Developers- Isolation Frameworks Fundamentals

High-Quality Automated Tests

High-Quality Automated Tests- Top 10 EditorConfig Coding Styles Part 2

This is the third article from the new series- High-Quality Automated Tests. In the first publication, I showed you how to apply coding standards and styles in

High-Quality Automated Tests- Top 10 EditorConfig Coding Styles Part 2

High-Quality Automated Tests

High-Quality Automated Tests- Consistent Coding Styles Using EditorConfig

This is the first article from a new series of posts called- High-Quality Automated Tests. I firmly believe that all coded tests should be treated with respect

High-Quality Automated Tests- Consistent Coding Styles Using EditorConfig

High-Quality Automated Tests

Testing for Developers- Unit Testing Fundamentals

In the series we will define the basic terms that every developer needs to know about testing. The purpose is to give all team members a shared understanding of

Testing for Developers- Unit Testing Fundamentals
Anton Angelov

About the author

Anton Angelov is Managing Director, Co-Founder, and Chief Test Automation Architect at Automate The Planet — a boutique consulting firm specializing in AI-augmented test automation strategy, implementation, and enablement. He is the creator of BELLATRIX, a cross-platform framework for web, mobile, desktop, and API testing, and the author of 8 bestselling books on test automation. A speaker at 60+ international conferences and researcher in AI-driven testing and LLM-based automation, he has been recognized as QA of the Decade and Webit Changemaker 2025.