+ Start a Discussion

100% Test Coverage Code not deploying

Hey Everyone - thanks in advance for all of the great advice I've been getting here. I wouldn't be anywhere near where I am now with my programming without the guidance provided in this forum & I am humbled by the insight you all provide.


I am in need of some insight as to why one of my classes won't deploy to my production org. In my sandbox it says I have 100% test coverage. When I go to deploy, it says I have only 23% coverage, and that the 'expected' result of my string replace is very different from what it should be. It appears that none of the methods (except the first one) are being tested by the test code for some reason???


The code is below, and the errors are listed below that.



public class String_functions{ Opportunity opp; public String_functions(ApexPages.StandardController controller) { opp = (Opportunity)controller.getRecord(); opp = [select id, Shipping_Address__c, Pricing__c, Delivery__c, Payment_Terms_Override__c, Warranty__c, StageName, CloseDate, name,Special__c, Adders_Optional_Scope_of_Supply__c, Tender_Name_or_Reason_for_Quotation__c, Commissioning_Start_up_Training__c from opportunity where id = :opp.id]; } public string getReasonText() { string paragraph = opp.Tender_Name_or_Reason_for_Quotation__c.replaceAll('\n','<br/>'); return paragraph; } public string getSpecialText() { string paragraph1 = opp.Special__c.replaceAll('\n','<br/>'); return paragraph1; } public string getTrainingText() { string paragraph2 = opp.Commissioning_Start_up_Training__c.replaceAll('\n','<br/>'); return paragraph2; } public string getAddersText() { string paragraph3 = opp.Adders_Optional_Scope_of_Supply__c.replaceAll('\n','<br/>'); return paragraph3; } public string getWarrantyText() { string paragraph4 = opp.Warranty__c.replaceAll('\n','<br/>'); return paragraph4; } public string getPaymentText() { string paragraph5 = opp.Payment_Terms_Override__c.replaceAll('\n','<br/>'); return paragraph5; } public string getDeliveryText() { string paragraph6 = opp.Delivery__c.replaceAll('\n','<br/>'); return paragraph6; } public string getPricingText() { string paragraph7 = opp.Pricing__c.replaceAll('\n','<br/>'); return paragraph7; } public string getShippingText() { string paragraph8 = opp.Shipping_Address__c.replaceAll('\n','<br/>'); return paragraph8; } //****************** //Test Method //****************** public static testMethod void TestString_functions() { // Insert test Opportunity Opportunity testOppty = new opportunity ( Name = 'Test Opportunity', Amount = 5000, StageName = 'Closed Won', CloseDate = System.today(), Tender_Name_or_Reason_for_Quotation__c ='test\ntest2\ntest3\ntest4', Commissioning_Start_up_Training__c ='test\ntest2\ntest3\ntest4', Special__c ='test\ntest2\ntest3\ntest4', Adders_Optional_Scope_of_Supply__c ='test\ntest2\ntest3\ntest4', Pricing__c ='test\ntest2\ntest3\ntest4', Warranty__c ='test\ntest2\ntest3\ntest4', Payment_Terms_Override__c ='test\ntest2\ntest3\ntest4', Delivery__c ='test\ntest2\ntest3\ntest4', Shipping_Address__c ='test\ntest2\ntest3\ntest4'); insert testOppty; // Instantiate VisualForce Page // PageReference pg = Page.Quote; // Test.setCurrentPage(pg); // ApexPages.currentPage().getParameters().put('id', testOppty.id); // Instantiate String_function controller ApexPages.StandardController s = new ApexPages.standardController(testOppty); String_functions qe = new String_functions(s); // Test: getReason_Text string paragraphTest1= qe.getReasonText(); System.assertEquals (paragraphTest1, 'test<br/>test2<br/>test3<br/>test4'); // Test: getSpecial_Text string paragraphTest2= qe.getSpecialText(); System.assertEquals (paragraphTest2, 'test<br/>test2<br/>test3<br/>test4'); // Test: getTraining_Text string paragraphTest3= qe.getTrainingText(); System.assertEquals (paragraphTest3, 'test<br/>test2<br/>test3<br/>test4'); // Test: getAdders_Text string paragraphTest4= qe.getAddersText(); System.assertEquals (paragraphTest4, 'test<br/>test2<br/>test3<br/>test4'); // Test: getWarranty_Text string paragraphTest5= qe.getWarrantyText(); System.assertEquals (paragraphTest5, 'test<br/>test2<br/>test3<br/>test4'); // Test: getPayment_Text string paragraphTest6= qe.getPaymentText(); System.assertEquals (paragraphTest6, 'test<br/>test2<br/>test3<br/>test4'); // Test: getDelivery_Text string paragraphTest7= qe.getDeliveryText(); System.assertEquals (paragraphTest7, 'test<br/>test2<br/>test3<br/>test4'); // Test: getPricing_Text string paragraphTest8= qe.getPricingText(); System.assertEquals (paragraphTest8, 'test<br/>test2<br/>test3<br/>test4'); // Test: getShipping_Text string paragraphTest9= qe.getShippingText(); System.assertEquals (paragraphTest9, 'test<br/>test2<br/>test3<br/>test4'); } } //The End


 Run Failures:
  String_functions.TestString_functions System.Exception: Assertion Failed: Expected: test test2 test3 test4, Actual: test<br/>test2<br/>text3<br/>test4


String_functions(ApexClass)--24 lines not tested, 23% covered


line 15, column 19 not covered

line 17, column 6 not covered

line 18, column 6 not covered 

line 21, column 17 not covered 

line 23, column 6 not covered 

line 24, column 6 not covered 

line 27, column 19 not covered 

line 29, column 6 not covered 

line 30, column 6 not covered 

line 33, column 21 not covered 

line 35, column 6 not covered 

line 36, column 6 not covered 

line 39, column 23 not covered 

line 41, column 6 not covered 

line 42, column 6 not covered 

line 45, column 23 not covered 

line 47, column 6 not covered 

line 48, column 6 not covered 

line 51, column 23 not covered 

line 53, column 6 not covered 

line 54, column 6 not covered 

line 57, column 19 not covered 

line 59, column 6 not covered 

line 60, column 6 not covered 


Thanks again for any help/insight you can provide!



Best Answer chosen by Admin (Salesforce Developers) 

I figured out the problem and thought I would post it for anyone who may experience the same thing.


It turns out that one of the fields being referenced was a TEXT field type instead of a LONG TEXT field type. The text field didn't want to recognize the replacement of \n to <br/>. Once I changed the field in my production org my code validated 100% again.


Hope this helps anyone else who may be experiencing the same problem.


Cheers -