You need to sign in to do that
Don't have an account?
Test class fails to validate deployment to production, not on dev
I have written a test that runs 100% successfully on the full development environment. When I attempt to validate deployment to the production server, it fails with the 'External Entry Point' Error on the last assert in my leadTransferTest() method. I have compared the objects on both the production and dev environments and cannot find any difference. Any help/suggestions would be greatly appreciated!!
private class LeadUtilsControllerTest {
static testMethod void leadTransferTest() {
//Create a Region
Region__c region = new Region__c();
region.Name = 'San Francisco';
insert region;
//Create a Zone
Zone__c zone = new Zone__c();
zone.Region__c = region.Id;
zone.Name = 'Zone 1';
//Create a Zipcode
Zip_Code__c zipcode = new Zip_Code__c();
zipcode.Zone__c = zone.Id;
zipcode.Name = '94002';
//Create a Lead
Lead lead = new Lead();
lead.Company = 'Company Name';
lead.FirstName = 'FName';
lead.LastName = 'LName';
lead.Region__c = 'San Francisc';
lead.PostalCode = '94002';
insert lead;
//Start test
test.startTest();
//Set Current Page
PageReference currPage = new PageReference('/apex/LeadUtils');
System.test.setCurrentPage(currPage);
//Initialize Controller
LeadUtilsController controller = new LeadUtilsController();
//Set old and new regions
controller.oldRegion = 'San Francisc';
controller.newRegion = 'San Francisco';
//Check to see if getItems has more than 0 items
System.assert(controller.getItems().size() > 0);
//Run transfer method
controller.updateRegion();
//Requery the leads
Lead leadTest = [SELECT Id, PostalCode, Region__c, ZipCode__c FROM Lead WHERE Id = :lead.Id];
system.debug('--TEST lead.Region__c before method:' + lead.Region__c);
system.debug('--TEST leadTest.Region__c after method:' + leadTest.Region__c);
system.debug('--TEST controller.newRegion:' + controller.newRegion);
//Assert that the lead's region was changed
System.assert(leadTest.Region__c == controller.newRegion);
//Stop test
test.stopTest();
}
static testMethod void leadTransferFailedTest() {
//Create a Region
Region__c region = new Region__c();
region.Name = 'San Francisco';
insert region;
//Create a Zone
Zone__c zone = new Zone__c();
zone.Region__c = region.Id;
zone.Name = 'Zone 1';
//Create a Zipcode
Zip_Code__c zipcode = new Zip_Code__c();
zipcode.Zone__c = zone.Id;
zipcode.Name = '94002';
//Create a Lead
Lead lead = new Lead();
lead.Company = 'Company Name';
lead.FirstName = 'FName';
lead.LastName = 'LName';
lead.Region__c = 'San Francisc';
lead.ZipCode__c = zipcode.Id;
lead.PostalCode = '85220';
insert lead;
//Start test
test.startTest();
//Set Current Page
PageReference currPage = new PageReference('/apex/LeadUtils');
System.test.setCurrentPage(currPage);
//Initialize Controller
LeadUtilsController controller = new LeadUtilsController();
//Set old and new regions
controller.oldRegion = 'San Francisc';
controller.newRegion = 'San Francisco';
//Run transfer method
controller.updateRegion();
//Stop test
test.stopTest();
//Assert that there was an error message
System.assert(ApexPages.hasMessages(ApexPages.Severity.ERROR));
}
static testMethod void leadRemapTest() {
//Create a Region
Region__c region = new Region__c();
region.Name = 'San Francisco';
insert region;
//Create a Zone
Zone__c zone = new Zone__c();
zone.Region__c = region.Id;
zone.Name = 'Zone 1';
//Create a Zipcode
Zip_Code__c zipcode = new Zip_Code__c();
zipcode.Zone__c = zone.Id;
zipcode.Name = '94002';
//Create a Lead
Lead lead = new Lead();
lead.Company = 'Company Name';
lead.FirstName = 'FName';
lead.LastName = 'LName';
lead.Region__c = 'San Francisco';
lead.PostalCode = '94002';
insert lead;
//Start test
test.startTest();
//Set Current Page
PageReference currPage = new PageReference('/apex/LeadUtils');
System.test.setCurrentPage(currPage);
//Initialize Controller
LeadUtilsController controller = new LeadUtilsController();
//Set old and new regions
controller.newRegionMap = 'San Francisco';
//Run remap method
controller.remapRegion();
//Assert that there was no error message
System.assert(ApexPages.hasMessages(ApexPages.Severity.INFO));
//Stop test
test.stopTest();
}
static testMethod void leadRemapNoLeadsTest() {
//Start test
test.startTest();
//Set Current Page
PageReference currPage = new PageReference('/apex/LeadUtils');
System.test.setCurrentPage(currPage);
//Initialize Controller
LeadUtilsController controller = new LeadUtilsController();
//Set old and new regions
controller.newRegionMap = 'San Francisco';
//Run remap method
controller.remapRegion();
//Assert that there was no error message
System.assert(ApexPages.hasMessages(ApexPages.Severity.ERROR));
//Stop test
test.stopTest();
}
}
I realized there is no insert on the zone and zipcode in the test....once I put this in there, it works 100%.
Thanks for looking into it.
All Answers
Did you get a line number for the error? Somewhere in the error it should tell you where you tripped up. That can help narrow down the problem.
It's line 79:
//Assert that the lead's region was changed
System.assert(leadTest.Region__c == controller.newRegion);
The log reaches it's maximum size before this test can dump it's info into the log, so unfortunately I don't know how to get any other information from it.
It should also say "expected x, received y" or something to that effect. What is the full error message?
The output in the Test Deployment Results View is:
Failures >> LeadUtilsControllerTest >> leadTransferTest >> System.AssertException: Assertion Failed >> Class.LeadUtilsControllerTest.leadTransferTest: line 79, column 3 External entry point
Debug Log: MAXIMUM DEBUG LOG SIZE REACHED (before it even gets to my test)
By the way, thank you for helping me look into this.
I realized there is no insert on the zone and zipcode in the test....once I put this in there, it works 100%.
Thanks for looking into it.
That's a good catch - I hadn't noticed.
Speaking of catching, you may want to put your inserts in try/catch blocks so you can output errors more gracefully. Then you can get more information if things fail for any reason.
Good suggestion. I am new to the world of Apex, so I will keep that in mind. Thanks again!!