We are an ISV partner and looking for ways to automate our tests for our package. We are looking for something like Mockito for Java and have found ApexMocks library, which is built on top of Stub API. However, it seems like we need to include the code in our package, which is a considerable disadvantage. On the other hand, I've heard people use Selenium for testing but as far as I know it is UI testing.

Our goal is to minimize manual testing for our package and make sure new changes do not break existing functionalities (proper unit tests and regression testing). Moreover, it would be nice to minimize our test run time and have our package upload faster. Looking for an optimal solution to solve this.

  • When uploading, only code optimization will improve the time it takes to run tests. When uploading all tests are ran regardless of if they were just ran immediately prior to packaging. I would be glad to be wrong here
    – Eric
    Aug 21, 2017 at 15:02

1 Answer 1


If we were starting again we would quite possibly use the ApexMocks library. Will be interesting to see if anyone posts an answer here on how to avoid having to include it in every package. Would also be interesting to know what performance gain they got from mocking vs using the database.

If you choose not to go the ApexMocks route, the simplest approach is to give up on the aspiration of being able to run tests quickly and just work with the real database in your Apex tests. The Apex test framework has some features that help such as rolling back (most) changes made when tests run and an @TestSetup mechanism. This approach will run quicker and be less fragile than trying to do all testing through the UI with Selenium. We have Continuous Integration setup via Jenkins, so although the tests take an hour to run (we have 2000+ tests), most developers only run a few tests themselves and leave Jenkins to do the tedious part. But yes the package upload process is equally slow which is frustrating.

(The platform mandates 75% Apex test coverage so Selenium on its own is not an option.)

  • When you say "most changes" what is not rolled back during tests? I always though everything was rolled back (sans auto-number depending on the setting)
    – Eric
    Aug 21, 2017 at 15:00
  • 1
    @Eric The auto-numbering was on my mind - don't know if there is anything else.
    – Keith C
    Aug 21, 2017 at 15:07
  • Isn't there a setting under Setup > Apex Test Execution > Options that can give tests their own auto numbers so they don't mess with production numbers?
    – dsharrison
    Aug 21, 2017 at 16:37
  • @dsharrison Yes Eric mentioned that in his comment. I'm just not sure if once that is checked everything is rolled back but it may be.
    – Keith C
    Aug 21, 2017 at 16:47

You must log in to answer this question.

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