Detect test folders separate from main class folders
Creating a new DX project (via sfdx force:project:create
) yields this structure (declarative folders removed):
.
├── config
├── force-app
│ └── main
│ └── default
│ ├── classes
│ ├── lwc
│ └── triggers
└── scripts
├── apex
└── soql
I mentioned in other tickets that we have 29 IC2 modules (so far) in our monorepo DX project, and of those, most have Apex code. In those modules/packages, we decided to put the tests in a separate folder, so we have this structure instead (taken from a blog post one of our devs saw):
.
├── config
└── force-app
├── main
│ └── default
│ ├── classes
│ └── triggers
└── test
└── apex
└── classes
When we create a new project from our repo, IC2 correctly detects all of the modules, and it detects the force-app/test/apex/classes
folders as source folders. However, once the project is created, the entry in all of the .iml
files looks like this:
<sourceFolder url="file://$MODULE_DIR$/force-app/test/apex/classes" isTestSource="false" />
Since these were not detected as test folders, when we open up one of the test files we’re missing functionality (such as the ability to click the green arrow in the gutter to run a single test). We have a script that we run to find all .iml
files with this entry, and set it to isTestSource="true"
.
So the ask on this ticket is for IC2 to automatically detect test folders within modules. There don’t seem to be any rules around test folder or file naming, but you could make a pretty good guess (sorta Jeff Foxworthy style):
- If a folder other than
force-app/main/default/classes
is detected that contains Apex classes, and and a folder one or more levels above is named eithertest
ortests
, it’s probably a test folder. - If a folder other than
force-app/main/default/classes
is detected that contains Apex classes, and a preponderance of the file names in the folder either start or end withTest
(case-insensitive), it’s probably a test folder. - If you want to be more precise (but have to parse or grep files instead of just list them), if a preponderance of files in a detected folder other than
force-app/main/default/classes
contain the@IsTest
annotation, it’s probably a test folder.
Comments (2)
-
repo owner -
repo owner - changed status to resolved
Delivered in 2.2.5.5.
- Log in to comment
This should be fixed in the next build (targeting Thursday morning).