Prompt the user when they create a non-test Apex class called FooTest

Issue #2546 duplicate
Aidan Harding created an issue

It’s a silly mistake that I make all the time:

  1. I intend to create a test class
  2. I fill in the name as WhateverImTestingTest
  3. I mindlessly click on Class instead of Unit Test Class
  4. The file is created using the normal class template instead of a test one

It would be nice if IC could notice that the name ends in Test and ask me if I meant to pick Unit Test Class as the type. I know it’s totally my own fault, but I make this mistake most of the time that I create a test class. I’m probably not the only one, so it would be a nice catch to save me from my own fast clicking.

Comments (6)

  1. Scott Wells repo owner
    • changed status to open

    I certainly understand the request. It's actually a bit simpler with something like the Exception class template because, in Apex, all Exception type names must end with Exception. There's no such requirement around unit test class names, though, and while some (most?) folks end them with Test, some start them with Test. It's possible that others don't even include the term Test in the name, though I imagine that's unlikely. I think if I were to validate around this, I'd a) need to make that validation configurable; b) need to check for the term Test in the name and not just that it ends in Test. Let me chew on this one a bit...

  2. Aidan Harding reporter

    Thanks, Scott,

    I know it’s a bit of an imperfect idea. As you say, naming is not consistent. FWIW, I think that having “Test” anywhere in the name could cause too many false positives. I’ve certainly worked in a few orgs where tests were part of their domain e.g. a company that does sound insulation testing for building sites, or one that does online learning with assessments.

    I know that for me, this feature would be a nice one. But I get that you have to balance it against adding more code and/or annoying other users.

  3. Scott Wells repo owner

    Agreed. I think the only way this could work properly is if it included an optional user-configured naming pattern for Apex unit test classes, perhaps with a default of .*Test, and clearing that pattern would disable that type of validation. Otherwise it’s probably going to bother as many users as it helps.

  4. Scott Wells repo owner

    There is another issue that requests something very similar. I’ll rationalize and merge shortly.

  5. Log in to comment