6

I'm sorry for the cryptic title.

I'm curious what tests are forced to run when deploying to production, if that production org contains unlocked packages. Lets say we have the following test classes and the package they're contained in:

  1. TestClass1.cls, contained in unlocked package A
  2. TestClass2.cls, not contained in any package

If I choose to deploy TestClass2.cls to production with the option of only running Local tests, will TestClass1.cls be executed?

The reason I'm asking, is that our unit tests takes a long time to execute when deploying to production, and if we can reduce the amount of unit tests needed to run, by packaging our code into unlocked packages, it might be worth looking in to.

1 Answer 1

1

Currently, tests are not enforced, but this is coming in the future.

Computing code coverage helps validate that the Apex code in your unlocked packages has adequate test coverage. Starting in Winter ‘21, a minimum 75% code coverage is required for package version promotion. Package versions created in Winter ‘21 and later, that don’t meet this code coverage, can only be installed in scratch orgs and sandboxes.

However, this applies when the package version is promoted, not when installing. Packages that are in released status can be deployed with no unit tests run at all. This this one of the major advantages of Unlocked Packages.

It also forces you to have generally 75% coverage in your org, since you can't install those packages without this coverage. This is similar to today's model where installing apps from the AppExchange don't run their tests during installation, allowing for rapid installation in most cases.

Only the tests in the package need to be run, and only during version promotion, thus moving the deployment times down while driving the validation times up, but since this only applies to promotions, it's overall faster than repeatedly failing because of coverage issues.

While we're not currently using this for production, the tests I've tried this on will potentially reduce our deployments from 30-40 minutes to about ... 1 minute. We're looking forward to this, but we have close to 40,000 metadata files we have to convert to Unlocked Packages (via dependencies), which has taken significant time. The end result should be worth the effort many times over.

3
  • Thank you for a great answer. It seems there's potential for vastly improving deploy times. However, it doesn't address my main question, i.e. will unit tests in package A be run, if I deploy TestClass2 to production which is NOT contained in that package?
    – Andreas86
    Jul 1, 2020 at 7:08
  • 1
    I just tried this my self in a trailhead hands-on org. First, I installed an unlocked package to the org. Then I deployed a package.zip containing an apex class, and also setting testlevel=RunLocalTests. This did NOT force the execution of unit tests inside the installed package. I wonder if a hands-on org is the same as a production org.
    – Andreas86
    Jul 1, 2020 at 12:25
  • @Andreas86 Hands-on orgs, Scratch Orgs, Developer Editions, etc are all not production orgs. Those are strictly defined as "orgs you've signed a contract for".
    – sfdcfox
    Jul 1, 2020 at 14:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .