4

So I have this test Class, when I run the test from inside Salesforce it fails. When I run the test from the Dev Console it passes. Why are the results different when I invoke the test from a different interface?

Just to be completely clear, when I describe running the test from inside Salesforce, I mean Setup -> Develop -> Apex Test Execution (select the test and run it).

When I describe running it from the Dev Console it's Test -> New Run -> (Select the test Class and run it).

The test also fails when validating a change set, however, change set deployments don't seem to be reporting the failure.

The nature of the failure is due to a DML exception that appears to be related to something build in Process Builder.

Are Apex tests run differently depending on how they are invoked?

1 Answer 1

3

Yes, there's runTests() and compileAndTest(), and they do run differently. In theory, they should run identically, but typically because of platform bugs, they do not. In those situations, you should try to get a bug opened with R&D. There's usually a workaround, but without support's help, it may be hard to pinpoint what needs to be done. Usually, compileAndTest will allow deployments that runTests reports as failures.

2
  • Also, long-running test or CPU timeout is quite frequent on sandbox, in prod it just runs fine Commented Feb 7, 2019 at 19:56
  • 2
    @PranayJaiswal that might simply be different TraceFlag settings, too. Setting debug levels too high (e.g. everything set to maximum trace levels) can cause CPU timeouts. Unless you're actually debugging, it's usually worthwhile to disable logging.
    – sfdcfox
    Commented Feb 7, 2019 at 20:05

You must log in to answer this question.

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