I have optimized almost all my test classes but the "Run All Tests" execution time is still not reduced.
I ran the tests in my full copy sandbox and it took 28 minutes. There are about 464 test classes. Some of the test classes have 50 to 60 test methods as the class demands so. If I remove the testmethod, the test coverage is getting reduced. If I write more test methods, the deployment time taken is too long. I just trying to keep a balance between my coverage % and the no. of methods.
Currently while deploying to production it takes about 1.5 hours. So I have optimized my code and gave a run all test in my sandbox it takes about 28 minutes. But if I run in someother time it takes only 16 minutes.
Not sure how much time it will take when I am deploying to production? How do I find and reduce this time taken to deploy?
For Example, I have attached a result of a test class here (which is one of the test classes from run all tests).
If you notice this image, There are totally 19 methods and the 1st highlighted method shown above is taking 6 mins 43 seconds but the 2nd method highlighted takes only 21 seconds. But the code for both the methods are almost the same.
Code for highighted method 1 :-
public static testmethod void TestAddFooterDisclaimerAndHelp()
{
//See Data and Cookie
createDataAndCookie();
Test.startTest();
//Invoke CloneSiteContent for Footer Copyright
AddSiteContent('Footer Copyright');
//Add Content - approveAndPublish
siteConDetail.ContentRichText = 'Test Add Footer Copyright Approve and Publish';
CompanyListPopulate(siteConDetail.BTP);
siteConDetail.approveAndPublish();
//Invoke CloneSiteContent for Site Disclaimer
AddSiteContent('Site Disclaimer');
//Invoke CloneSiteContent for Help
AddSiteContent('Help');
Test.stopTest();
}
Code for Highlighted method 2 :-
public static testmethod void TestEditFooterDisclaimerAndHelp()
{
//See Data and Cookie
createDataAndCookie();
Test.startTest();
//Invoke EditSiteContent for Footer Copyright
EditSiteContent('SiteContent', 'Footer Copyright');
//Edit Content - approveAndPublish
siteConDetail.ContentRichText = 'Test Edit Footer Copyright Approve and Publish';
siteConDetail.ChangeLogNotes = 'Test';
CompanyListPopulate(siteConDetail.BTP);
siteConDetail.approveAndPublish();
//Invoke EditSiteContent for Site Disclaimer
EditSiteContent('SiteContent', 'Site Disclaimer');
//Invoke EditSiteContent for Help
EditSiteContent('SiteContent', 'Help');
Test.stopTest();
}
Not sure why its making a difference. I guess it should be because its waiting for some other method in Run all tests to complete. If that is the case how can we determine the actual runtime of a test method and how can we optimize it?
Also I have tested each of the test classes separately and its just executing in a few seconds even for the ones which has about 60 test methods, but when I run it together sometimes the same class alone takes 17 minutes. Can some one help / guide me here correctly as to what I need to do for reducing the time to deploy in production?
* Edited Part *
I still couldn't figure out how to reduce the time. FYI, I am using change sets to deploy to production.