4

My organization has a mishmash of apex classes, both regular classes that execute specific business logic and test classes that execute unit tests on those regular classes. When we started developing on the platform we really didn't know what we were doing, so we didn't enforce any kind of naming convention on class names. For example, one developer might have created a class called ShowDay and an accompanying test class called ShowDayTest. Another developer might have a class called Host_Validate with test class called Host_Validate_Test. There are two problems with this for me:

(1) When looking at a list of all of the classes in the Force.com IDE or in the Salesforce UI, all the classes are there in a big jumble, whether they are test or not. I'd love to be able to see my test classes separate from all others. I can't quite articulate why except for the fact that I just feel like it would help me organize things better.

(2) The inconsistent naming convention leads to all kinds of weird class names. It would be nice to have one convention that's clean, consistent, and makes sense. However, I don't want to implement such a convention if it's outside of what's considered "normal."

Are there any best practices here?

  • 2
    I like to append Test and name it the same as the related class, so that the code shows up alongside in the directory view. – greenstork Nov 11 '14 at 0:35
  • If that's the best practice then I'll do it. I just find that contributes a bit to the jumble. I wish I could segment them in some way. – eyedar Nov 11 '14 at 0:42
  • ah, yes @DanielBallinger...that looks like I'm looking for... – eyedar Nov 11 '14 at 0:45
  • 1
    Same name with Test suffix only. It's what Salesforce do. :P – bigassforce Nov 11 '14 at 1:22
1

I like my regular apex classes and test classes to sort together, so I append "_Test". Greenstork's practice of appending "Test" is similar.

You say you want all the tests to sort together. I've generally found I'm more likely to want a regular class and the test that goes with it rather than all tests. Your mileage, of course, may vary.

Both wishes can be satisfied. If you append "_Text" ( or similar), you can build a view where you look for a class name that contains "_Text". That view will show all classes that you have named using that convention (as long as "_Text" occurs nowhere else).

Not the answer you're looking for? Browse other questions tagged or ask your own question.