function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jasondoddsjasondodds 

Exclude manage package tests when setting runalltests=true with Ant migration tool

I sm trying to setup a continuous integration process for our org and I am running into an issue that I can find no solution for.  We have re-created all of our sandboxes and they now contain managed packages with Apex test failures (due to custom field validations, etc.).  I have found no way to run an Ant deployment to a sandbox and run only the tests that are NOT included in the managed packages (like you would get if you set runalltests=false, but deploy to a production org).  Every build we run to our integration sandbox fails because we get Apex failures from the managed packages, even though all of our tests pass.

Below is the path we are using to promote code (this process is not unique within our company or continuous integration lifecycle in general):
  1. Develop code in developer's sandbox.
  2. Check-in code to source control (for us it is Git/GitHub)
  3. Jenkins build job monitors commits to GitHub master branch and runs a deploy to Integration sandbox when changes are found.  All tests are run during build <deploy runalltests=true> (FAIL)
  4. The QA runs a manual Jenkins job to deploy master branch to QA sandbox.  All tests are run during build <deploy runalltests=true> (FAIL)
  5. After QA, the master branch is pushed to the Staging sandbox via Jenkins for user acceptance testing.  No tests are run <deploy runalltests=false> (PASS)
  6. Code is deployed to Production org using Jenkins build.  During this deployment process, runAllTests= false, so only the non-managed Apex test code gets executed <deploy runalltests=false> (PASS)
I'm sure other people have run into this, but is there any solution?
Ashish_SFDCAshish_SFDC
Hi Jason, 


See the below article will help, 

1. Do run-all-tests execute in production when deploying regardless of what you're deploying?

- No, some components deployed alone won't trigger tests. This document in the metadata API describes which component will invoke validation:
http://www.salesforce.com/us/developer/docs/api_meta/Content/meta_deploy_running_tests.htm
2. Does "run-all-tests" includes running managed package tests?
- Yes
3. Is there a way to exclude running managed package tests when deploying or is it only possible to ignore the errors generated by these?
- Managed package tests will not be executed when deploying to production, unless you are deploying a managed package.
4. Does code coverage for managed packages test classes contribute to the overall org code coverage?
- The code coverage value computed by "Calculate your organization's code coverage" may differ from the code coverage value computed after running all unit tests using Run All Tests.  This is because "Calculate your organization's code coverage" excludes classes that are part of installed managed packages while Run All Tests doesn't.
5. What is the result of setting the runAllTests flag to true in production vs. in sandbox?
- runAllTests is a boolean parameter causing the following behavior:
In Production - if set to false, then managed package tests will not run but every other test will run.
In Sandbox - if set to false, no tests will run.


http://help.salesforce.com/apex/HTViewSolution?id=000003620&language=en_US

Post again if you have any further questions, 


Regards,
Ashish


jasondoddsjasondodds
The article listed in your response is a re-hash of what I explained in the question.
Ashish_SFDCAshish_SFDC
Hi Jason, 


This is a little workaround:

public with sharing class AdministrationTools {
public static PageReference startLocalTests() {
List<List<ApexClass>> searchList = [FIND '@isTest' IN ALL FIELDS RETURNING ApexClass (Id WHERE NamespacePrefix = NULL AND Status = 'Active')];
ApexTestQueueItem[] queueItems = new List<ApexTestQueueItem>();
for(ApexClass myResults : searchList[0]) {
   queueItems.add(new ApexTestQueueItem(ApexClassId=myResults.Id));
}
insert queueItems;
PageReference newocp = new PageReference('/ui/setup/apex/ApexTestQueuePage');
       newocp.setRedirect(true);
       return newocp;
}
}

Then just you can call it via Anonymous or using an administrator Apex page like:
<apex:page controller="AdministrationTools">
    <apex:form>
        <apex:commandButton action="{!startLocalTests}" value="Start local tests" />
    </apex:form>
</apex:page>


posted on the Idea:

https://success.salesforce.com/ideaview?id=08730000000IfJFAA0


Also see the similar dicussion in the link below, 

The only way to avoid running specific tests when deploying is to use the Ant Migration Tool:

https://success.salesforce.com/answers?id=90630000000gw9LAAQ


Regards,
Ashish
David EspositoDavid Esposito
@jasondodds -- I too was frustrated by this and ended up writing an ant scriptdef that brute forces the call to the compileAndTest ant task. Rather than pasting the source code here, I'll just link to the stackexchange answer I wrote up:

http://salesforce.stackexchange.com/a/42162/2533