6

I have a sandbox org (not scratch org). I authenticated it with alias e-devint

When run RunLocalTests (hundreds apex test files), it fails quickly with the error below. The error doesn't tell much. It is the same error without -y parameter.

How can I troubleshooting?

sfdx force:apex:test:run -y --testlevel RunLocalTests -w 600 -r human -u e-devint
ERROR running force:apex:test:run:  Unable to invoke async test job: An unknown exception occurred.

Try this:
Try running the tests in the Developer Console by using force:org:open, or create a new scratch org and try again.

When running only one or several tests, the result returns well, like below:

sfdx force:apex:test:run -y -n SwagOfferPropertyTest -w 600 -r human -u e-devint
=== Test Results
TEST NAME                                             OUTCOME  MESSAGE  RUNTIME (MS)
────────────────────────────────────────────────────  ───────  ───────  ────────────
SwagOfferPropertyTest.test1         Pass              408
SwagOfferPropertyTest.test2  Pass              379
5
  • 3
    Have you tried to "Compile all classes" (found in Setup > Develop > Apex Classes)? If you have any compile-fail dependencies, this can cause all kinds of unusual errors.
    – sfdcfox
    Apr 29, 2019 at 12:02
  • thanks @sfdcfox, most likely this is the reason, there are indeed multiple apex compiling failures. We will fix failures and see if the command runs
    – Xi Xiao
    Apr 29, 2019 at 12:11
  • maybe I need a new thread... how come apex compiling failures appear since the code needs to be compiled before deploying? the dependencies are not strictly checked? @sfdcfox
    – Xi Xiao
    Apr 29, 2019 at 12:13
  • Run Tests don't compile or deploy anything, aside from compile-on-demand if the code cache needs to be regenerated (rare). In production, dependencies are strictly enforced, but in other orgs, you can easily place your code into an invalid state (e.g. by modifying or deleting a class), and these may not be caught until the next full compile/test execution.
    – sfdcfox
    Apr 29, 2019 at 12:20
  • good new information, thanks again! It would be nice if you had your comments in a reply so I could mark it as "answer" :)
    – Xi Xiao
    Apr 29, 2019 at 13:22

1 Answer 1

7

Unlike Production orgs, Sandboxes, Scratch Orgs, and Developer Orgs only compile some of the code when you make changes. As such, it's possible to cause a class or trigger to become invalid by deleting/renaming/moving a method, changing its parameters, deleting a class, etc without causing any immediate errors. If you place your org in this state, it can also cause unit tests to fail, since they cannot compile without the missing code. You can check for this condition by using Setup > Develop > Apex Classes > Compile all classes. Depending on which classes are affected, you may get "unknown exceptions", "Status: CompileFail", or other unusual error messages. At that point, you need to fix whatever problems are present in your compilation failures before you will be able to run all local tests again.

You must log in to answer this question.

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