Deployment task in large organization is cumbersome process because you have n number of test classes in your Production environment and Salesforce runs all those classes to maintain robustness of platform which is good in on way but at other end it is very time consuming process, one of my company’s client has more that 1000 of test methods to run and it is generally takes 2-3 hours.

So when we think about the solution of this problem we can come up with following solutions.

1. Run tests only for what I am deploying.

2. Don’t run test methods if I am deploying general components without apex code.

3. Don’t run managed package test methods.

Thanks to Salesforce for their summer’s 15 release they came up with some great solutions to decrease the deployment time from 2-3 hours to 20-30 mins.

1. Run Specific test while deploying to PROD

I always prefer ant deployment tool over changeset because it gives more control while we perform deployment task and Salesforce help you to think the same that is why they have given you an option to urn specific test while deploying to PROD. if you are familiar with ant deployment you already know that ant deployment depends on build.xml file which contains different target defined. build.xml contains something like this.

 <target name="deploy">
<sf:deploy username="USERNAME" password="PASSWORD" checkOnly="false" serverurl="https://login.salesforce.com" deployRoot="retrieveMetadata" logType="Detail"/>
</target>

You can now add testLevel in above xml file in following way.

 <target name="deploy">
<sf:deploy testLevel="RunSpecifiedTests" username="USERNAME" password="PASSWORD" checkOnly="false" serverurl="https://login.salesforce.com" deployRoot="retrieveMetadata" logType="Detail"/>
 <runTest>TestClass1</runTest>
 <runTest>TestClass2</runTest>
 <runTest>TestClass3</runTest>
</target>

in following way you can simply decrease deployment time in Salesforce and run only specific test methods.

2. Avoid managed package test methods

If you want to You can avoid managed package test methods you can define testLevel as LocalTest in following way.

 <target name="deploy">
<sf:deploy testLevel="RunLocalTests" username="USERNAME" password="PASSWORD" checkOnly="false" serverurl="https://login.salesforce.com" deployRoot="retrieveMetadata" logType="Detail"/>
 <runTest>TestClass1</runTest>
 <runTest>TestClass2</runTest>
 <runTest>TestClass3</runTest>
</target>

You can read more in Salesforce release notes

Happy Coding!!!!!