- changed status to open
Prompt the user when they create a non-test Apex class called FooTest
It’s a silly mistake that I make all the time:
- I intend to create a test class
- I fill in the name as WhateverImTestingTest
- I mindlessly click on Class instead of Unit Test Class
- 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)
-
repo owner -
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.
-
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. -
repo owner There is another issue that requests something very similar. I’ll rationalize and merge shortly.
-
repo owner - removed version
Removing version: Unassigned (automated comment)
-
repo owner - changed status to duplicate
Duplicate of #1946.
- Log in to comment
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 withTest
, some start them withTest
. It's possible that others don't even include the termTest
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 termTest
in the name and not just that it ends inTest
. Let me chew on this one a bit...