I am woefully lacking in my Class writing skills. I'm curious if anyone can tell me (or give an example that works) why I cannot seem to get many, if any, IF...TRUE statements to be covered by Code Coverage in my Classes? Screenshot attached. Pretty much ALL of my TRUE results are NOT covered, but most of my FALSEs are. Huh??
UPDATED 1130AM EST: Here is the class in question. This class is probably pathetic by normal standards and it pre-dated me, for which I have simply added code from time to time to "get by". I just want to add enough to get my code to clear. :-(
@isTest
private class mtinsfhTestClass {
static testMethod void testLead1() /* ----- Lead Testing Section ----- */
{
Lead leadRec = new Lead();
leadRec.FirstName = 'DSG';
leadRec.LastName = 'DSGTestClassRecord Lead';
leadRec.Phone = '4696751677';
leadRec.Email = 'test1@test.com';
leadRec.LeadSource = 'FXCT DEMO';
leadRec.Lead_Source_Detail__c = 'FXCT DEMO';
leadRec.Status = 'New Lead';
insert leadRec;
}
static testMethod void testLead2() /*------------------------*/
{
Lead leadRec = new Lead();
leadRec.FirstName = 'DSG';
leadRec.LastName = 'DSGTestClassRecord Lead';
leadRec.Phone = '4696751677';
leadRec.Email = 'test2@test.com';
insert leadRec;
}
static testMethod void testAcct1111() /* ----- Account Testing Section ----- */
{
Account acctRec = new Account();
acctRec.Name = 'DSGTestClassRecord Account';
acctRec.Phone = '4696751677';
acctRec.pb_RecordType_UTP_OnDemand__c = '4696751677';
acctRec.IP_Address__c = 'test text only';
insert acctRec;
}
static testMethod void testTask11() /* ----- Task Testing Section ----- (plus Opportunity) */
{
Lead objL = new Lead();
objL.LastName = 'DSGTestClassRecord Lead';
objL.Company = 'Test Company';
objL.Status = 'New Lead';
objL.Email = 'TestEmail11@test.com';
insert objL;
Lead leadRec = [select id from Lead where LastName = 'DSGTestClassRecord Lead' and Status='New Lead' and Email <> null limit 1];
Task taskRec1 = new Task();
taskRec1.WhoId = leadRec.Id;
taskRec1.Activity_Type__c = 'Phone Call';
taskRec1.Status = 'Complete';
insert taskRec1;
Opportunity o = new Opportunity();
o.Name = 'DSGTestClassRecord Opportunity';
o.StageName = 'New';
o.Sub_Stage__c = 'NewSub';
o.CloseDate = Date.today();
insert o;
// Opportunity oppRec = [select id from Opportunity where Name = 'DSGTestClassRecord Opportunity' Limit 1];
Opportunity OppRec = [select Id From Opportunity Where id=: o.Id];
oppRec.StageName = 'Closed Lost';
oppRec.LeadSource = 'Test 1';
oppRec.Promotions_Received__c = 'abc; 123; xyz;';
update oppRec;
Task taskRec3 = [select Id From Task Where whoId = :leadRec.Id Limit 1];
delete taskRec3;
delete oppRec;
}
static testMethod void testTask12() /*------------------------*/
{
Lead objL = new Lead();
objL.LastName = 'DSGTestClassRecord Lead';
objL.Company = 'Test Company';
objL.Email = 'TestEmail12@test.com';
insert objL;
Lead leadRec = [select id from Lead where LastName = 'DSGTestClassRecord Lead' and Email <> null limit 1];
Task taskRec1 = new Task();
taskRec1.WhoId = leadRec.Id;
taskRec1.Activity_Type__c = 'Webinar Attendance';
taskRec1.Status = 'Complete';
taskRec1.Event_Date__c = Date.today();
taskRec1.Attended__c = true;
insert taskRec1;
Task taskRec3a = [select Id From Task Where whoId = :leadRec.Id Limit 1];
taskRec3a.Attended__c = true;
update taskRec3a;
taskRec3a.Attended__c = false;
update taskRec3a;
Task taskRec3 = [select Id From Task Where whoId = :leadRec.Id Limit 1];
delete taskRec3;
}
static testMethod void testTask13() /*------------------------*/
{
Account objL2 = new Account();
objL2.Name = 'DSGTestClassRecord Account';
String tempChartTxt = 'Charting';
objL2.put('pb_SubBegin_' + tempChartTxt + '__c' , Date.today() );
objL2.put('pb_CurrSubBeg_' + tempChartTxt + '__c' , Date.today() );
objL2.put('pb_SubEnd_' + tempChartTxt + '__c' , Date.today() );
objL2.put('pb_PrevSubEnd_' + tempChartTxt + '__c' , Date.today() );
insert objL2;
Account acctRec = [select id from Account where Name = 'DSGTestClassRecord Account' limit 1];
Task taskRec11 = new Task();
taskRec11.WhatId = acctRec.Id;
taskRec11.Activity_Type__c = 'Webinar Attendance';
taskRec11.Status = 'Complete';
taskRec11.Event_Date__c = Date.today();
taskRec11.Attended__c = true;
insert taskRec11;
Task taskRec13 = [select Id From Task Where whatId = :acctRec.Id Limit 1];
delete taskRec13;
}
static testMethod void testOpportunity111() /*------------------------*/
{
Lead leadRec = new Lead();
leadRec.FirstName = 'DSG';
leadRec.LastName = 'DSGTestClassRecord Lead';
leadRec.Phone = '4696751677';
leadRec.Email = 'test3@test.com';
leadRec.LeadSource = 'FXCT DEMO';
leadRec.Lead_Source_Detail__c = 'FXCT DEMO';
leadRec.Status = 'New Lead';
insert leadRec;
Lead leadRec31=[select id from Lead where LastName='DSGTestClassRecord Lead' limit 1];
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(leadRec31.Id);
LeadStatus convertstatus = [select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
lc.setConvertedStatus(convertStatus.MasterLabel);
Database.LeadConvert[] lcArray = new Database.LeadConvert[] {lc};
Database.LeadConvertResult[] results = Database.convertLead(lcArray);
System.assert(results[0].IsSuccess());
Opportunity o2 = new Opportunity();
o2.Name = 'DSGTestClassRecord Opportunity 2';
o2.StageName = 'New';
o2.Sub_Stage__c = 'Cancelled';
o2.CLoseDate = Date.today();
insert o2;
// Opportunity OppRec1 = [select Id From Opportunity Where Name = 'DSGTestClassRecord Opportunity 2'];
Opportunity OppRec1 = [select Id From Opportunity Where id=: o2.Id];
OppRec1.StageName = 'Closed Won';
OppRec1.Sub_Stage__c = 'Refund';
OppRec1.Opportunity_Discount_Approved__c = true;
OppRec1.put('Charting_Start__c' , Date.today() );
OppRec1.put('Charting_Expiration__c' , Date.today() );
OppRec1.put('Purchase_Amount__c' , 1234.56 );
oppRec1.put('Promotions_Received__c' , 'abc; 123; xyz 2;' );
oppRec1.put('Promotions_Received_Used__c' , true );
update OppRec1;
Integer NumClosedWons = 0;
oppRec1.Sub_Stage__c = 'Paid';
NumClosedWons++;
oppRec1.Purchase_Amount__c = 123.54;
update OppRec1;
}
}