function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mahesh GorrepatiMahesh Gorrepati 

can we make method name in a test class same as class name for test class in apex salesforce

can we make method name in a test class same as class name for test class in apex salesforce
SwethaSwetha (Salesforce Developers) 
HI Mahesh,

In Apex Salesforce, it is not recommended to have a method name same as the class name. Although it is allowed to define a method with the same name as that of a class, it can lead to confusion and make the code harder to read and maintain.

It is recommended to follow the naming conventions and use meaningful names for classes and methods. To write a test class in Apex Salesforce, you can name the test class the same as the class being tested, but you need to append the word "Test" to the end of the class name.

For example, if you have a class named "MyClass", the corresponding test class should be named "MyClassTest". This naming convention is recommended to ensure consistency and clarity in your code.

Also see 
https://developer.salesforce.com/forums/?id=9062I000000BlR8QAK
https://salesforce.stackexchange.com/questions/356916/how-can-i-write-apex-classes-that-share-the-same-name-as-standard-or-custom-obje
https://github.com/forcedotcom/salesforcedx-vscode/issues/923

If this information helps, please mark the answer as best. Thank you
Krishna VKrishna V
Hello Mahesh, 

Just to call out few best practices for apex class and method naming conventions in Salesforce, we name the class with a generic name that explains what that is class is being built for. Example - BusinessRulesEngine.cls for a class that implements logic based on some business rules and processBusinessRuleOne as the name of the method, which explains what that method is doing to the point. This keeps the code base clean and easier to follow.

There are no restrictions around naming your method the same as your class, so if that makes sense in your use case, feel free to do so. It is just not the best practice. 

Please mark it as Best Answer if the above information was helpful.

Thanks,
Krishna