+ Start a Discussion
SalesforceCrm AccountCRMSalesforceCrm AccountCRM 

System.AssertException: Assertion Failed error in test class

When i run a test class the system throws an error as
if i uncomment the line ,the system throws an error :
System.AssertException: Assertion Failed

System.assert(mc1res.New_to_EnterpriseDB__c);
If comment the above line ,then the method gets passed .
Trigger :
 
public class CampaignMemberFunctions {

    // Sets the CampaignMember New_to_Enterprise_Db field if lead was created in lsat 6 hours
    // Call during CampaignMember before create trigger 
    public static void UpdateNewToEnterpriseDB(CampaignMember cm, Lead ld)
    {
         if(ld.CreatedDate.addHours(6) > DateTime.Now()) cm.New_to_EnterpriseDB__c = true;
    }
    
     
    // Updates the lead or contact status based on sync logic. Returns True if update occurred
    // ld or ct must be valid. If ct is valid, ct.Account.Customer_Status__c must be valid.
    // Note for developers - yes, it's not the most efficient possible code, but is clear, and leaves flexibility
    // for more complex mappings later.
    public static Boolean SyncStatus(CampaignMember cm, Lead ld, Contact ct, Map<String, CMStatusSettings__c> statusmap)
    {
        Boolean result = true;
        String newvalue;
        
        if(ct!= null)
        {
            if(statusmap.containsKey(cm.Response_Status__c))
            {
                newvalue = statusmap.get(cm.Response_Status__c).StatusMapping__c;
                if(newvalue == ct.Status__c)
                {
                    result = false;
                }
                else
                {
                    ct.Status__c = newvalue;
                }
            } else if(cm.Response_Status__c == 'Disqualified' || 
                        cm.Response_Status__c == 'Qualified - New Opportunity' ||
                        cm.Response_Status__c == 'Closed - Converted' )
            {
                newvalue = 'Closed - ' + ct.Account.Customer_Status__c + ' Account';
                if(ct.Status__c == newvalue)
                {
                    result = false;
                }
                else
                {
                    ct.Status__c = newvalue;
                }
                if(cm.Response_Status__c == 'Disqualified')
                {   // Set nuture time on disqualified status
                    Date newtimeout = Date.today().addDays((CMScoreEngine__c.getInstance('Default').NurtureTimeoutDays__c).intValue());
                    if(ct.Admin_Nurture_Timeout__c != newtimeout || ct.Lead_Score__c !=0 || ct.Campaign_Score__c !=0) result = true;
                    ct.Admin_Nurture_Timeout__c = newtimeout;
                    ct.Lead_Score__c = 0; 
                    ct.Campaign_Score__c = 0;   // Probably aren't using this one
                }
            } else
            {
                result = false;
            }       
            /*if(cm.Response_Status__c=='Contacted-Warm' && cm.Do_not_reassign_to_Landings__c) 
            {
                ct.Do_not_reassign_to_Landings__c = true;
                result = true;
            }*/
            
            
        }
        
        else if(ld!=null)
        {
            if(statusmap.containsKey(cm.Response_Status__c))
            {
                newvalue = statusmap.get(cm.Response_Status__c).StatusMapping__c;
                if(newvalue==ld.Status)
                {
                    result = false;
                }
                else
                {
                    ld.Status = newvalue;
                }
            } else if(cm.Response_Status__c == 'Disqualified')
            {
                if(ld.Status=='Disqualified' && ld.Disqaulified_Reason__c == cm.Disqualified_Reason__c)
                {
                    result = false;
                }
                else
                {
                    ld.Status = 'Disqualified';
                    ld.Disqaulified_Reason__c = cm.Disqualified_Reason__c;
                    System.Debug('Disqualified reason being set to: ' + cm.Disqualified_Reason__c);
                }
            } else
            {
                result = false;
            }
            /*if(cm.Response_Status__c=='Contacted-Warm' && cm.Do_not_reassign_to_Landings__c) 
            {
                ld.Do_not_reassign_to_Landings__c = true;
                result = true;
            }*/
        } 
        return(result);
    
    }
    
    // Search through the converted leads, opportunities and campaignmembers to sync if necessary
    public static void SyncAfterConversion(Map<Id,Lead> convertedleads, Map<Id, Opportunity>convertedops, Map<Id, CampaignMember> possiblecms) 
    {
        for(Lead ld: convertedleads.values())
        {
            // Grab the campaign member - this must be correct by original query
             CampaignMember cm = new CampaignMember();
             
             System.debug('@@@@@possiblecms.get(ld.admin_CMSourceId__c)'+possiblecms.get(ld.admin_CMSourceId__c));
             cm = possiblecms.get(ld.admin_CMSourceId__c);
             System.debug('@@@@@cm '+cm );
           if(cm!=null)
           {  
            // We know this lead is converted. Let's get the opportunity.             
            if(ld.ConvertedOpportunityId != null)
            {
                Opportunity opp = convertedops.get(ld.ConvertedOpportunityId);
                opp.PMM_stage__c = cm.PMM_Stage__c;
                opp.Product_Interest__c = cm.Product_Interest__c;
                opp.Buyer__c = cm.Buyer__c;
                opp.New_to_EnterpriseDB__c = cm.New_to_EnterpriseDB__c;
                opp.Problem_to_Solve__c = cm.Problem_to_Solve__c;
                opp.Any_OSS_in_current_stack__c = cm.Any_OSS_in_current_stack__c;
                opp.Total_of_Databases_in_your_Org__c = cm.Total_of_Databases_in_your_Org__c;
                opp.Primary_Database__c = cm.Primary_Database__c;
                opp.of_Postgres_Database_Servers__c = cm.of_Postgres_Database_Servers__c;
                opp.Just_learning_about_EnterpriseDB__c = cm.Just_learning_about_EnterpriseDB__c;
                opp.Project_Requires_a_Net_New_DB__c = cm.Project_Requires_a_Net_New_DB__c;
                opp.Timeframe_To_Production__c = cm.Timeframe_To_Production__c;
                opp.Budget__c = cm.Budget__c;
                opp.User__c = cm.User__c;
                opp.Champion__c = cm.Champion__c;
                opp.Decision_Maker__c = cm.Decision_Maker__c;
                cm.Response_Status__c = 'Qualified - New Opportunity';
                cm.Opportunity_Name__c = opp.Id;
                cm.Opportunity_Create_Date__c = Date.Today();
            }
            
            else
            {                          
                if(cm.lead.status!=null)
                 {
                    cm.Response_Status__c = cm.lead.status;
                 }
            }
            cm.admin_IsConverted__c = true; 
          }           
        }   
    
    }
    
    public static void EmailErrorMessage(String message)
    {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(new String[] {'edbnotify@bearcavern.com', 'roanbear@gmail.com'});
        mail.setSenderDisplayName('APEX notifier');
        mail.setSubject('SFDC/Eloqua Data Creation Error');
        mail.setPlainTextBody(message);
        List<Messaging.SendEmailResult> results = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        for(Messaging.SendEmailResult r: results)
        {
            System.debug('Result of Email sent ' + r.isSuccess());
            if(!r.isSuccess())
            {
                for(Messaging.SendEmailError sme: r.getErrors())
                {
                    for(String s: sme.getFields())  System.Debug('Error for field ' + s );      
                    System.Debug('Error message ' + sme.getMessage());
                    System.Debug('StatusCode ' + sme.getStatusCode());
                }
            }
        }
        
    }

}
Part of Test Class Written :
@isTest
Public class TestCampaignMemberFunctions {

   //Checking for if Condition value Response_Status__c= Disqualified 
    Public static testMethod void TestCreationDate() {
      
       Test.StartTest();
        
        Lead ld2 = [select ID, CreatedDate, IsConverted from LEAD where CreatedDate < :DateTime.Now().addHours(-7) and IsConverted=False  LIMIT 1];
        Campaign cam = new Campaign(Name='campname');      
        insert cam;       
        Account a = new Account();
        a.Name ='My Company';
        Insert a;                   
        
        Lead ld = new Lead();
        ld.Company='colead1';  
        ld.LastName ='colead1_'+String.valueOf(System.now());
        ld.status= 'Disqualified';        
        ld.admin_CMSourceId__c= cam.Id;
        ld.Disqaulified_Reason__c='Disqualified';              
        insert ld;
        
        Contact con = new Contact(LastName ='Test');        
        Insert con;               
       // Test.StartTest();
        CampaignMember mc1 = new CampaignMember(CampaignId = cam.Id,Product_Interest__c='Services',Response_Status__c='Disqualified',status= 'Disqualified',PMM_Stage__c='Learns of Postgres', LeadId=ld.Id);
        CampaignMember mc2 = new CampaignMember(CampaignId = cam.Id, LeadId=ld2.Id);
        insert mc1;
        insert mc2; 
        Opportunity opp =new Opportunity();
        opp.Product_Interest__c='Services';
       
        opp.PMM_stage__c ='Deployment';
        opp.Buyer__c = 'xyz';
        opp.New_to_EnterpriseDB__c =True;
        opp.Problem_to_Solve__c ='Performance' ;
        opp.Any_OSS_in_current_stack__c ='OS' ;
        opp.Total_of_Databases_in_your_Org__c ='500';
        opp.Primary_Database__c =mc1.Primary_Database__c;
        opp.of_Postgres_Database_Servers__c = mc1.of_Postgres_Database_Servers__c;
        opp.Just_learning_about_EnterpriseDB__c = mc1.Just_learning_about_EnterpriseDB__c;
        opp.Project_Requires_a_Net_New_DB__c = mc1.Project_Requires_a_Net_New_DB__c;
        opp.Timeframe_To_Production__c = mc1.Timeframe_To_Production__c;
        opp.Budget__c = mc1.Budget__c;
        opp.User__c = mc1.User__c;
        opp.Champion__c = mc1.Champion__c;
        opp.Decision_Maker__c =mc1.Decision_Maker__c;
                
        opp.Name='Testing';
        opp.StageName='Closed Lost';
        opp.CloseDate=System.today(); 
        Insert opp;       
        CampaignMember mc1res = [Select Id, New_to_EnterpriseDB__c,Response_Status__c from CampaignMember where Id = :mc1.id ];
        CampaignMember mc2res = [Select Id, New_to_EnterpriseDB__c from CampaignMember where Id = :mc2.id ];        
        System.assert(mc1res.New_to_EnterpriseDB__c);
        System.assert(! mc2res.New_to_EnterpriseDB__c);
        
        Map<String, CMStatusSettings__c> statusmap = new Map<String, CMStatusSettings__c>();
       // statusmap.put(mc1res.Response_Status__c, custSetting);
                  
        Map<Id,Lead> convertedleads = new Map<Id,Lead>();                   
        convertedleads.put(ld.Id,ld);
        
        Map<Id, Opportunity> convertedops= new Map<Id, Opportunity>();        
        convertedops.put(opp.Id,opp);
          
        Map<Id, CampaignMember> possiblecms= new Map<Id, CampaignMember>();        
        possiblecms.put(mc1.Id,mc1);                                 
        CampaignMemberFunctions  cmf = new CampaignMemberFunctions();
        CampaignMemberFunctions.SyncStatus( mc1res,ld,con,statusmap);
        System.debug('@@@@@convertedleads'+convertedleads);
        System.debug('@@@@@possiblecms'+possiblecms);
        System.debug('@@@@@convertedops'+convertedops);
                
        CampaignMemberFunctions.SyncAfterConversion(convertedleads,convertedops,possiblecms);
        CampaignMemberFunctions.EmailErrorMessage('testmessage');     
        Test.StopTest();    
        }
}
Any help very much appreciated.


 
John Pipkin 14John Pipkin 14
SalesforceCrm, 

It doesn't look like your method "UpdateNewToEnterpriseDB" is being called anywhere. In the test class, you are asserting that the checkbox was checked, but if the method is never called, then it would not be checked. 

If you remove assert statements, the only way a test class fails is if it runs into a system exception or validation rule. Just becuase a test passes does not mean that the code is working as expected. That is why assert statements are important to ensure the code is functioning properly.

Hope that helps
SalesforceCrm AccountCRMSalesforceCrm AccountCRM
@John Pipkin 14 :Thanks for the response .
As Suggested i tried adding the method ,but the system throws an error as :
Error: Compile Error: expecting a right parentheses, found 'cm' at line 97 column 71

 CampaignMemberFunctions.UpdateNewToEnterpriseDB(CampaignMember cm, Lead ld);
Any help very much appreciated.
 
John Pipkin 14John Pipkin 14
The inputs of the method need to be variables that are set in the trigger. for instance, If you have a campaignmember record set to a variable, "myCampMember", and a lead record set to a variable, "myLead", then you would call  the method by saying
 
CampaignMemberFunctions.UpdateNewToEnterpriseDB(myCampMember, myLead);

 
SalesforceCrm AccountCRMSalesforceCrm AccountCRM
@John Pipkin 14 :When i use the inputs of the trigger given ,
THe varibles are defined in the trigger
public static void UpdateNewToEnterpriseDB(CampaignMember cm, Lead ld)
When i use

CampaignMemberFunctions.UpdateNewToEnterpriseDB(cm,ld)
then the system throws an error as
Error	Error: Compile Error: Variable does not exist: cm at line 97 column 57
Similarly when i use the other variable used in test class as
CampaignMemberFunctions.UpdateNewToEnterpriseDB(mc1,ld);
Run test class ,Throws an error as :
System.AssertException: Assertion Failed
Class.TestCampaignMemberFunctions.TestCreationDate: line 77, column 1

line 77 :System.assert(mc1res.New_to_EnterpriseDB__c);
Any suggestion plz.


 
John Pipkin 14John Pipkin 14
Until you can have the trigger to call the method, the test class will not work. Test classes test the functionality of triggers (among other things) so if your trigger is not calling it, then your test class will fail if it is asserting that the trigger called it. 

"Variable does not exist: cm" error means that you are trying to use "cm" and is it not defined as a variable. 

Please post the code where you are trying to call the method and I will give some more specific guidance. The original post included only the helper and test class, not the trigger. 
SalesforceCrm AccountCRMSalesforceCrm AccountCRM
@John Pipkin 14 :

Trigger :
public class CampaignMemberFunctions {

    // Sets the CampaignMember New_to_Enterprise_Db field if lead was created in lsat 6 hours
    // Call during CampaignMember before create trigger 
    public static void UpdateNewToEnterpriseDB(CampaignMember cm, Lead ld)
    {
         if(ld.CreatedDate.addHours(6) > DateTime.Now()) cm.New_to_EnterpriseDB__c = true;
    }
    
     
    // Updates the lead or contact status based on sync logic. Returns True if update occurred
    // ld or ct must be valid. If ct is valid, ct.Account.Customer_Status__c must be valid.
    // Note for developers - yes, it's not the most efficient possible code, but is clear, and leaves flexibility
    // for more complex mappings later.
    public static Boolean SyncStatus(CampaignMember cm, Lead ld, Contact ct, Map<String, CMStatusSettings__c> statusmap)
    {
        Boolean result = true;
        String newvalue;
        
        if(ct!= null)
        {
            if(statusmap.containsKey(cm.Response_Status__c))
            {
                newvalue = statusmap.get(cm.Response_Status__c).StatusMapping__c;
                if(newvalue == ct.Status__c)
                {
                    result = false;
                }
                else
                {
                    ct.Status__c = newvalue;
                }
            } else if(cm.Response_Status__c == 'Disqualified' || 
                        cm.Response_Status__c == 'Qualified - New Opportunity' ||
                        cm.Response_Status__c == 'Closed - Converted' )
            {
                newvalue = 'Closed - ' + ct.Account.Customer_Status__c + ' Account';
                if(ct.Status__c == newvalue)
                {
                    result = false;
                }
                else
                {
                    ct.Status__c = newvalue;
                }
                if(cm.Response_Status__c == 'Disqualified')
                {   // Set nuture time on disqualified status
                    Date newtimeout = Date.today().addDays((CMScoreEngine__c.getInstance('Default').NurtureTimeoutDays__c).intValue());
                    if(ct.Admin_Nurture_Timeout__c != newtimeout || ct.Lead_Score__c !=0 || ct.Campaign_Score__c !=0) result = true;
                    ct.Admin_Nurture_Timeout__c = newtimeout;
                    ct.Lead_Score__c = 0; 
                    ct.Campaign_Score__c = 0;   // Probably aren't using this one
                }
            } else
            {
                result = false;
            }       
            /*if(cm.Response_Status__c=='Contacted-Warm' && cm.Do_not_reassign_to_Landings__c) 
            {
                ct.Do_not_reassign_to_Landings__c = true;
                result = true;
            }*/
            
            
        }
        
        else if(ld!=null)
        {
            if(statusmap.containsKey(cm.Response_Status__c))
            {
                newvalue = statusmap.get(cm.Response_Status__c).StatusMapping__c;
                if(newvalue==ld.Status)
                {
                    result = false;
                }
                else
                {
                    ld.Status = newvalue;
                }
            } else if(cm.Response_Status__c == 'Disqualified')
            {
                if(ld.Status=='Disqualified' && ld.Disqaulified_Reason__c == cm.Disqualified_Reason__c)
                {
                    result = false;
                }
                else
                {
                    ld.Status = 'Disqualified';
                    ld.Disqaulified_Reason__c = cm.Disqualified_Reason__c;
                    System.Debug('Disqualified reason being set to: ' + cm.Disqualified_Reason__c);
                }
            } else
            {
                result = false;
            }
            /*if(cm.Response_Status__c=='Contacted-Warm' && cm.Do_not_reassign_to_Landings__c) 
            {
                ld.Do_not_reassign_to_Landings__c = true;
                result = true;
            }*/
        } 
        return(result);
    
    }
    
    // Search through the converted leads, opportunities and campaignmembers to sync if necessary
    public static void SyncAfterConversion(Map<Id,Lead> convertedleads, Map<Id, Opportunity>convertedops, Map<Id, CampaignMember> possiblecms) 
    {
        for(Lead ld: convertedleads.values())
        {
            // Grab the campaign member - this must be correct by original query
             CampaignMember cm = new CampaignMember();
             
             System.debug('@@@@@possiblecms.get(ld.admin_CMSourceId__c)'+possiblecms.get(ld.admin_CMSourceId__c));
             cm = possiblecms.get(ld.admin_CMSourceId__c);
             System.debug('@@@@@cm '+cm );
           if(cm!=null)
           {  
            // We know this lead is converted. Let's get the opportunity.             
            if(ld.ConvertedOpportunityId != null)
            {
                Opportunity opp = convertedops.get(ld.ConvertedOpportunityId);
                opp.PMM_stage__c = cm.PMM_Stage__c;
                opp.Product_Interest__c = cm.Product_Interest__c;
                opp.Buyer__c = cm.Buyer__c;
                opp.New_to_EnterpriseDB__c = cm.New_to_EnterpriseDB__c;
                opp.Problem_to_Solve__c = cm.Problem_to_Solve__c;
                opp.Any_OSS_in_current_stack__c = cm.Any_OSS_in_current_stack__c;
                opp.Total_of_Databases_in_your_Org__c = cm.Total_of_Databases_in_your_Org__c;
                opp.Primary_Database__c = cm.Primary_Database__c;
                opp.of_Postgres_Database_Servers__c = cm.of_Postgres_Database_Servers__c;
                opp.Just_learning_about_EnterpriseDB__c = cm.Just_learning_about_EnterpriseDB__c;
                opp.Project_Requires_a_Net_New_DB__c = cm.Project_Requires_a_Net_New_DB__c;
                opp.Timeframe_To_Production__c = cm.Timeframe_To_Production__c;
                opp.Budget__c = cm.Budget__c;
                opp.User__c = cm.User__c;
                opp.Champion__c = cm.Champion__c;
                opp.Decision_Maker__c = cm.Decision_Maker__c;
                cm.Response_Status__c = 'Qualified - New Opportunity';
                cm.Opportunity_Name__c = opp.Id;
                cm.Opportunity_Create_Date__c = Date.Today();
            }
            
            else
            {                          
                if(cm.lead.status!=null)
                 {
                    cm.Response_Status__c = cm.lead.status;
                 }
            }
            cm.admin_IsConverted__c = true; 
          }           
        }   
    
    }
    
    public static void EmailErrorMessage(String message)
    {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(new String[] {'edbnotify@bearcavern.com', 'roanbear@gmail.com'});
        mail.setSenderDisplayName('APEX notifier');
        mail.setSubject('SFDC/Eloqua Data Creation Error');
        mail.setPlainTextBody(message);
        List<Messaging.SendEmailResult> results = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        for(Messaging.SendEmailResult r: results)
        {
            System.debug('Result of Email sent ' + r.isSuccess());
            if(!r.isSuccess())
            {
                for(Messaging.SendEmailError sme: r.getErrors())
                {
                    for(String s: sme.getFields())  System.Debug('Error for field ' + s );      
                    System.Debug('Error message ' + sme.getMessage());
                    System.Debug('StatusCode ' + sme.getStatusCode());
                }
            }
        }
        
    }

}

Test Class :
@isTest
Public class TestCampaignMemberFunctions {

   //Checking for if Condition value Response_Status__c= Disqualified 
    Public static testMethod void TestCreationDate() {
      
       Test.StartTest();
        
        Lead ld2 = [select ID, CreatedDate, IsConverted from LEAD where CreatedDate < :DateTime.Now().addHours(-7) and IsConverted=False  LIMIT 1];
        Campaign cam = new Campaign(Name='campname');      
        insert cam;       
        Account a = new Account();
        a.Name ='My Company';
        Insert a;                   
        
        Lead ld = new Lead();
        ld.Company='colead1';  
        ld.LastName ='colead1_'+String.valueOf(System.now());
        ld.status= 'Disqualified';        
        ld.admin_CMSourceId__c= cam.Id;
        ld.Disqaulified_Reason__c='Disqualified';              
        insert ld;
        
        Contact con = new Contact(LastName ='Test');        
        Insert con;               
       // Test.StartTest();
        CampaignMember mc1 = new CampaignMember(CampaignId = cam.Id,Product_Interest__c='Services',Response_Status__c='Disqualified',status= 'Disqualified',PMM_Stage__c='Learns of Postgres', LeadId=ld.Id);
        CampaignMember mc2 = new CampaignMember(CampaignId = cam.Id, LeadId=ld2.Id);
        insert mc1;
        insert mc2; 
        Opportunity opp =new Opportunity();
        opp.Product_Interest__c='Services';
       
        opp.PMM_stage__c ='Deployment';
        opp.Buyer__c = 'xyz';
        opp.New_to_EnterpriseDB__c =True;
        opp.Problem_to_Solve__c ='Performance' ;
        opp.Any_OSS_in_current_stack__c ='OS' ;
        opp.Total_of_Databases_in_your_Org__c ='500';
        opp.Primary_Database__c =mc1.Primary_Database__c;
        opp.of_Postgres_Database_Servers__c = mc1.of_Postgres_Database_Servers__c;
        opp.Just_learning_about_EnterpriseDB__c = mc1.Just_learning_about_EnterpriseDB__c;
        opp.Project_Requires_a_Net_New_DB__c = mc1.Project_Requires_a_Net_New_DB__c;
        opp.Timeframe_To_Production__c = mc1.Timeframe_To_Production__c;
        opp.Budget__c = mc1.Budget__c;
        opp.User__c = mc1.User__c;
        opp.Champion__c = mc1.Champion__c;
        opp.Decision_Maker__c =mc1.Decision_Maker__c;
                
        opp.Name='Testing';
        opp.StageName='Closed Lost';
        opp.CloseDate=System.today(); 
        Insert opp;       
        CampaignMember mc1res = [Select Id, New_to_EnterpriseDB__c,Response_Status__c from CampaignMember where Id = :mc1.id ];
        CampaignMember mc2res = [Select Id, New_to_EnterpriseDB__c from CampaignMember where Id = :mc2.id ];        
        System.assert(mc1res.New_to_EnterpriseDB__c);
        System.assert(! mc2res.New_to_EnterpriseDB__c);
        
        Map<String, CMStatusSettings__c> statusmap = new Map<String, CMStatusSettings__c>();
       // statusmap.put(mc1res.Response_Status__c, custSetting);
                  
        Map<Id,Lead> convertedleads = new Map<Id,Lead>();                   
        convertedleads.put(ld.Id,ld);
        
        Map<Id, Opportunity> convertedops= new Map<Id, Opportunity>();        
        convertedops.put(opp.Id,opp);
          
        Map<Id, CampaignMember> possiblecms= new Map<Id, CampaignMember>();        
        possiblecms.put(mc1.Id,mc1);                                 
        CampaignMemberFunctions  cmf = new CampaignMemberFunctions();
        CampaignMemberFunctions.SyncStatus( mc1res,ld,con,statusmap);
        System.debug('@@@@@convertedleads'+convertedleads);
        System.debug('@@@@@possiblecms'+possiblecms);
        System.debug('@@@@@convertedops'+convertedops);
                
        CampaignMemberFunctions.UpdateNewToEnterpriseDB(mc1,ld); 
        CampaignMemberFunctions.SyncAfterConversion(convertedleads,convertedops,possiblecms);
        CampaignMemberFunctions.EmailErrorMessage('testmessage');
           
        Test.StopTest();    
        }
        //Checking for if Condition value Response_Status__c= Qualified - New Opportunity
        Public static testMethod void TestCreationDate1() {
        
        Lead ld2 = [select ID, CreatedDate, IsConverted from LEAD where CreatedDate < :DateTime.Now().addHours(-7) and IsConverted=False  LIMIT 1];
        Campaign cam = new Campaign(Name='campname');      
        insert cam;       
        Account a = new Account();
        a.Name ='My Company';
        Insert a;                   
        
        Lead ld = new Lead();
        ld.Company='colead1';  
        ld.LastName ='colead1_'+String.valueOf(System.now());
        ld.status= 'Qualified - New Opportunity';        
        ld.admin_CMSourceId__c= cam.Id; 
        ld.Disqaulified_Reason__c='Qualified - New Opportunity';               
        insert ld;
        
        Contact con = new Contact(LastName ='Test');        
        Insert con;               
        Test.StartTest();
        CampaignMember mc1 = new CampaignMember(CampaignId = cam.Id,Product_Interest__c='Services',Response_Status__c='Qualified - New Opportunity',status= 'Qualified - New Opportunity', LeadId=ld.Id);
        CampaignMember mc2 = new CampaignMember(CampaignId = cam.Id, LeadId=ld2.Id);
        insert mc1;
        insert mc2; 
        Opportunity opp =new Opportunity();
        opp.Product_Interest__c=mc1.Product_Interest__c;
       
        opp.PMM_stage__c = mc1.PMM_Stage__c;
        opp.Buyer__c = mc1.Buyer__c;
        opp.New_to_EnterpriseDB__c =mc1.New_to_EnterpriseDB__c;
        opp.Problem_to_Solve__c = mc1.Problem_to_Solve__c;
        opp.Any_OSS_in_current_stack__c = mc1.Any_OSS_in_current_stack__c;
        opp.Total_of_Databases_in_your_Org__c = mc1.Total_of_Databases_in_your_Org__c;
        opp.Primary_Database__c =mc1.Primary_Database__c;
        opp.of_Postgres_Database_Servers__c = mc1.of_Postgres_Database_Servers__c;
        opp.Just_learning_about_EnterpriseDB__c = mc1.Just_learning_about_EnterpriseDB__c;
        opp.Project_Requires_a_Net_New_DB__c = mc1.Project_Requires_a_Net_New_DB__c;
        opp.Timeframe_To_Production__c = mc1.Timeframe_To_Production__c;
        opp.Budget__c = mc1.Budget__c;
        opp.User__c = mc1.User__c;
        opp.Champion__c = mc1.Champion__c;
        opp.Decision_Maker__c =mc1.Decision_Maker__c;
                
        opp.Name='Testing';
        opp.StageName='Closed Lost';
        opp.CloseDate=System.today(); 
        Insert opp;       
        CampaignMember mc1res = [Select Id, New_to_EnterpriseDB__c,Response_Status__c from CampaignMember where Id = :mc1.id ];
        CampaignMember mc2res = [Select Id, New_to_EnterpriseDB__c from CampaignMember where Id = :mc2.id ];        
        /*System.assert(mc1res.New_to_EnterpriseDB__c);
        System.assert(! mc2res.New_to_EnterpriseDB__c);*/
        
        Map<String, CMStatusSettings__c> statusmap = new Map<String, CMStatusSettings__c>();
        //statusmap.put(mc1res.Response_Status__c, custSetting);
                  
        Map<Id,Lead> convertedleads = new Map<Id,Lead>();                   
        convertedleads.put(ld.Id,ld);
        
        Map<Id, Opportunity> convertedops= new Map<Id, Opportunity>();        
        convertedops.put(opp.Id,opp);
          
        Map<Id, CampaignMember> possiblecms= new Map<Id, CampaignMember>();        
        possiblecms.put(mc1.Id,mc1);                                 
        CampaignMemberFunctions  cmf = new CampaignMemberFunctions();
        CampaignMemberFunctions.SyncStatus( mc1res,ld,con,statusmap);
        System.debug('@@@@@convertedleads'+convertedleads);
        System.debug('@@@@@possiblecms'+possiblecms);
        System.debug('@@@@@convertedops'+convertedops);
                
        CampaignMemberFunctions.SyncAfterConversion(convertedleads,convertedops,possiblecms);
        CampaignMemberFunctions.EmailErrorMessage('testmessage');     
        Test.StopTest();    
        } 
          //Checking for if Condition value Response_Status__c= Closed - Converted 
        Public static testMethod void TestCreationDate2() {
        
        Lead ld2 = [select ID, CreatedDate, IsConverted from LEAD where CreatedDate < :DateTime.Now().addHours(-7) and IsConverted=False  LIMIT 1];
        Campaign cam = new Campaign(Name='campname');      
        insert cam;       
        Account a = new Account();
        a.Name ='My Company';
        Insert a;                   
        
        Lead ld = new Lead();
        ld.Company='colead1';  
        ld.LastName ='colead1_'+String.valueOf(System.now());
        ld.status= 'Closed - Converted';        
        ld.admin_CMSourceId__c= cam.Id;
        ld.Disqaulified_Reason__c='Closed - Converted';              
        insert ld;
        
        Contact con = new Contact(LastName ='Test');        
        Insert con;               
        Test.StartTest();
        CampaignMember mc1 = new CampaignMember(CampaignId = cam.Id,Product_Interest__c='Services',Response_Status__c='Closed - Converted',status= 'Closed - Converted', LeadId=ld.Id);
        CampaignMember mc2 = new CampaignMember(CampaignId = cam.Id, LeadId=ld2.Id);
        insert mc1;
        insert mc2; 
        Opportunity opp =new Opportunity();
        opp.Product_Interest__c=mc1.Product_Interest__c;
       
        opp.PMM_stage__c = mc1.PMM_Stage__c;
        opp.Buyer__c = mc1.Buyer__c;
        opp.New_to_EnterpriseDB__c =mc1.New_to_EnterpriseDB__c;
        opp.Problem_to_Solve__c = mc1.Problem_to_Solve__c;
        opp.Any_OSS_in_current_stack__c = mc1.Any_OSS_in_current_stack__c;
        opp.Total_of_Databases_in_your_Org__c = mc1.Total_of_Databases_in_your_Org__c;
        opp.Primary_Database__c =mc1.Primary_Database__c;
        opp.of_Postgres_Database_Servers__c = mc1.of_Postgres_Database_Servers__c;
        opp.Just_learning_about_EnterpriseDB__c = mc1.Just_learning_about_EnterpriseDB__c;
        opp.Project_Requires_a_Net_New_DB__c = mc1.Project_Requires_a_Net_New_DB__c;
        opp.Timeframe_To_Production__c = mc1.Timeframe_To_Production__c;
        opp.Budget__c = mc1.Budget__c;
        opp.User__c = mc1.User__c;
        opp.Champion__c = mc1.Champion__c;
        opp.Decision_Maker__c =mc1.Decision_Maker__c;
                
        opp.Name='Testing';
        opp.StageName='Closed Lost';
        opp.CloseDate=System.today(); 
        Insert opp;       
        CampaignMember mc1res = [Select Id, New_to_EnterpriseDB__c,Response_Status__c from CampaignMember where Id = :mc1.id ];
        CampaignMember mc2res = [Select Id, New_to_EnterpriseDB__c from CampaignMember where Id = :mc2.id ];        
        /*System.assert(mc1res.New_to_EnterpriseDB__c);
        System.assert(! mc2res.New_to_EnterpriseDB__c);*/
        
        Map<String, CMStatusSettings__c> statusmap = new Map<String, CMStatusSettings__c>();
        //statusmap.put(mc1res.Response_Status__c, custSetting);
                  
        Map<Id,Lead> convertedleads = new Map<Id,Lead>();                   
        convertedleads.put(ld.Id,ld);
        
        Map<Id, Opportunity> convertedops= new Map<Id, Opportunity>();        
        convertedops.put(opp.Id,opp);
          
        Map<Id, CampaignMember> possiblecms= new Map<Id, CampaignMember>();        
        possiblecms.put(mc1.Id,mc1);                                 
        CampaignMemberFunctions  cmf = new CampaignMemberFunctions();
        CampaignMemberFunctions.SyncStatus( mc1res,ld,con,statusmap);
        System.debug('@@@@@convertedleads'+convertedleads);
        System.debug('@@@@@possiblecms'+possiblecms);
        System.debug('@@@@@convertedops'+convertedops);
                
        CampaignMemberFunctions.SyncAfterConversion(convertedleads,convertedops,possiblecms);
        CampaignMemberFunctions.EmailErrorMessage('testmessage');     
        Test.StopTest();    
        } 
        
        //Checking for if Condition value CMStatusSettings__c 
       Public static testMethod void TestCreationDate3() {
        
        Lead ld2 = [select ID, CreatedDate, IsConverted from LEAD where CreatedDate < :DateTime.Now().addHours(-7) and IsConverted=False  LIMIT 1];
        Campaign cam = new Campaign(Name='campname');      
        insert cam;       
        Account a = new Account();
        a.Name ='My Company';
        Insert a;                   
        
        Lead ld = new Lead();
        ld.Company='colead1';  
        ld.LastName ='colead1_'+String.valueOf(System.now());
        ld.status= 'newvalue';        
        ld.admin_CMSourceId__c= cam.Id;
        ld.Disqaulified_Reason__c='newvalue';
        ld.ConvertedOpportunityId=ld.Id; 
        insert ld;
        
        Contact con = new Contact(LastName ='Test');        
        Insert con;               
        Test.StartTest();
        CampaignMember mc1 = new CampaignMember(CampaignId = cam.Id,Product_Interest__c='Services',Response_Status__c='Disqualified',status= 'newvalue',PMM_Stage__c='Learns of Postgres', LeadId=ld.Id);
        CampaignMember mc2 = new CampaignMember(CampaignId = cam.Id, LeadId=ld2.Id);
        insert mc1;
        insert mc2; 
        Opportunity opp =new Opportunity();
        opp.Product_Interest__c=mc1.Product_Interest__c;
       
        opp.PMM_stage__c = mc1.PMM_Stage__c;
        opp.Buyer__c = mc1.Buyer__c;
        opp.New_to_EnterpriseDB__c =mc1.New_to_EnterpriseDB__c;
        opp.Problem_to_Solve__c = mc1.Problem_to_Solve__c;
        opp.Any_OSS_in_current_stack__c = mc1.Any_OSS_in_current_stack__c;
        opp.Total_of_Databases_in_your_Org__c = mc1.Total_of_Databases_in_your_Org__c;
        opp.Primary_Database__c =mc1.Primary_Database__c;
        opp.of_Postgres_Database_Servers__c = mc1.of_Postgres_Database_Servers__c;
        opp.Just_learning_about_EnterpriseDB__c = mc1.Just_learning_about_EnterpriseDB__c;
        opp.Project_Requires_a_Net_New_DB__c = mc1.Project_Requires_a_Net_New_DB__c;
        opp.Timeframe_To_Production__c = mc1.Timeframe_To_Production__c;
        opp.Budget__c = mc1.Budget__c;
        opp.User__c = mc1.User__c;
        opp.Champion__c = mc1.Champion__c;
        opp.Decision_Maker__c =mc1.Decision_Maker__c;
                
        opp.Name='Testing';
        opp.StageName='Closed Lost';
        opp.CloseDate=System.today(); 
        Insert opp;       
        CampaignMember mc1res = [Select Id, New_to_EnterpriseDB__c,Response_Status__c from CampaignMember where Id = :mc1.id ];
        CampaignMember mc2res = [Select Id, New_to_EnterpriseDB__c from CampaignMember where Id = :mc2.id ];        
        /*System.assert(mc1res.New_to_EnterpriseDB__c);
        System.assert(! mc2res.New_to_EnterpriseDB__c);*/
        
        CMStatusSettings__c custSetting =new CMStatusSettings__c();
        custSetting.Name= 'Test';
        insert custSetting;
       // statusmap.put(mc1res.Response_Status__c, custSetting);
        
        Map<String, CMStatusSettings__c> statusmap = new Map<String, CMStatusSettings__c>();
        statusmap.put(mc1res.Response_Status__c, custSetting);
                  
        Map<Id,Lead> convertedleads = new Map<Id,Lead>();                   
        convertedleads.put(ld.Id,ld);
        
        Map<Id, Opportunity> convertedops= new Map<Id, Opportunity>();        
        convertedops.put(opp.Id,opp);
          
        Map<Id, CampaignMember> possiblecms= new Map<Id, CampaignMember>();        
        possiblecms.put(mc1.Id,mc1);                                 
        CampaignMemberFunctions  cmf = new CampaignMemberFunctions();
        CampaignMemberFunctions.SyncStatus( mc1res,ld,con,statusmap);
        System.debug('@@@@@convertedleads'+convertedleads);
        System.debug('@@@@@possiblecms'+possiblecms);
        System.debug('@@@@@convertedops'+convertedops);
                
        CampaignMemberFunctions.SyncAfterConversion(convertedleads,convertedops,possiblecms);
        CampaignMemberFunctions.EmailErrorMessage('testmessage');     
        Test.StopTest();    
        } 
           //Checking for if Condition value LeadConvertion.
         Public static testMethod void TestCreationDate4() {
        
        Lead ld2 = [select ID, CreatedDate, IsConverted from LEAD where CreatedDate < :DateTime.Now().addHours(-7) and IsConverted=False  LIMIT 1];
        Campaign cam = new Campaign(Name='campname');      
        insert cam;       
        Account a = new Account();
        a.Name ='My Company';
        Insert a;                   
        
        Lead ld = new Lead();
        ld.Company='colead1';  
        ld.LastName ='colead1_'+String.valueOf(System.now());
        ld.status='Closed - Converted';        
        ld.admin_CMSourceId__c= cam.Id;
        ld.Disqaulified_Reason__c='Closed - Converted';
        ld.ConvertedOpportunityId=ld.Id; 
        insert ld;
        
        Contact con = new Contact(LastName ='Test');        
        Insert con;               
        Test.StartTest();
        CampaignMember mc1 = new CampaignMember(CampaignId = cam.Id,Product_Interest__c='Services',Response_Status__c='Closed - Converted',status= 'Closed - Converted',PMM_Stage__c='Learns of Postgres', LeadId=ld.Id);
        CampaignMember mc2 = new CampaignMember(CampaignId = cam.Id, LeadId=ld2.Id);
        insert mc1;
        insert mc2; 
        Opportunity opp =new Opportunity();
        opp.Product_Interest__c=mc1.Product_Interest__c;
       
        opp.PMM_stage__c = mc1.PMM_Stage__c;
        opp.Buyer__c = mc1.Buyer__c;
        opp.New_to_EnterpriseDB__c =mc1.New_to_EnterpriseDB__c;
        opp.Problem_to_Solve__c = mc1.Problem_to_Solve__c;
        opp.Any_OSS_in_current_stack__c = mc1.Any_OSS_in_current_stack__c;
        opp.Total_of_Databases_in_your_Org__c = mc1.Total_of_Databases_in_your_Org__c;
        opp.Primary_Database__c =mc1.Primary_Database__c;
        opp.of_Postgres_Database_Servers__c = mc1.of_Postgres_Database_Servers__c;
        opp.Just_learning_about_EnterpriseDB__c = mc1.Just_learning_about_EnterpriseDB__c;
        opp.Project_Requires_a_Net_New_DB__c = mc1.Project_Requires_a_Net_New_DB__c;
        opp.Timeframe_To_Production__c = mc1.Timeframe_To_Production__c;
        opp.Budget__c = mc1.Budget__c;
        opp.User__c = mc1.User__c;
        opp.Champion__c = mc1.Champion__c;
        opp.Decision_Maker__c =mc1.Decision_Maker__c;
                
        opp.Name='Testing';
        opp.StageName='Closed Lost';
        opp.CloseDate=System.today(); 
        Insert opp;       
        CampaignMember mc1res = [Select Id, New_to_EnterpriseDB__c,Response_Status__c from CampaignMember where Id = :mc1.id ];
        CampaignMember mc2res = [Select Id, New_to_EnterpriseDB__c from CampaignMember where Id = :mc2.id ];        
       /* System.assert(mc1res.New_to_EnterpriseDB__c);
        System.assert(! mc2res.New_to_EnterpriseDB__c);*/
        
        Map<String, CMStatusSettings__c> statusmap = new Map<String, CMStatusSettings__c>();
       // statusmap.put(mc1res.Response_Status__c, custSetting);
                  
        Map<Id,Lead> convertedleads = new Map<Id,Lead>(); 
         // START Convert the Lead into Test Class
        Database.LeadConvert lc = new Database.LeadConvert();
        lc.setLeadId(ld.Id);
       // lc.setOpportunityName('Testing'); 
        LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
        lc.setConvertedStatus(convertStatus.MasterLabel);
        Database.LeadConvertResult lcr = Database.convertLead(lc); 
        System.assert(lcr.isSuccess()); 
        convertedleads.put(ld.Id,ld);                  
        //convertedleads.put(ld.Id,ld);
        
        Map<Id, Opportunity> convertedops= new Map<Id, Opportunity>();        
        convertedops.put(opp.Id,opp);
          
        Map<Id, CampaignMember> possiblecms= new Map<Id, CampaignMember>();        
        possiblecms.put(mc1.Id,mc1);                                 
        CampaignMemberFunctions  cmf = new CampaignMemberFunctions();
        CampaignMemberFunctions.SyncStatus( mc1res,ld,con,statusmap);
        System.debug('@@@@@convertedleads'+convertedleads);
        System.debug('@@@@@possiblecms'+possiblecms);
        System.debug('@@@@@convertedops'+convertedops);
                
        CampaignMemberFunctions.SyncAfterConversion(convertedleads,convertedops,possiblecms);
        CampaignMemberFunctions.EmailErrorMessage('testmessage');     
        Test.StopTest();    
        } 
                        
}
Any help very much appreciated.
 
John Pipkin 14John Pipkin 14
CampaignMemberFunctions is not a trigger. Triggers are defined like below
Trigger [TriggerApiName] on [SObject] ( [before|after / insert|update|delete|undelete ] )

If you do not have a trigger defined, then that is your issue. 
SalesforceCrm AccountCRMSalesforceCrm AccountCRM
@John Pipkin 14 :It is a class.their is no trigger written .
John Pipkin 14John Pipkin 14
Ok I see. Then you will need to call line 76:
CampaignMemberFunctions.UpdateNewToEnterpriseDB(mc1,ld);

before calling line 56 and 57: 
System.assert(mc1res.New_to_EnterpriseDB__c);
System.assert(! mc2res.New_to_EnterpriseDB__c);

Since you are checking the functionality of UpdateNewToEnterpriseDB by asserting, you need to call the method first. Then assert what should happen.
 
SalesforceCrm AccountCRMSalesforceCrm AccountCRM
@John Pipkin 14 :As Suggested , i have given the below line before system.assert .
CampaignMemberFunctions.UpdateNewToEnterpriseDB(mc1,ld);
But now the system throws an error as :
System.NullPointerException: Attempt to de-reference a null object

Class.CampaignMemberFunctions.UpdateNewToEnterpriseDB: line 12, column 1
Class.TestCampaignMemberFunctions.TestCreationDate: line 77, column 1