function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
niharnihar 

Test Methods With No Assert result

Hi Everyone,

Can anyone help me in test class.
I have an error in test method assert .

User-added image
Test class :
 
@isTest
public class TwnxTest {

    //this method for testing with names as "Twilio"
    public static testmethod void testSmsFromTwnxWithNameAsTwilio(){        
        
        Contact con = new Contact(LastName='test',Phone='+19343213321');
        insert con;
        
        ApexPages.StandardController sc = new ApexPages.StandardController(con);
        
        Twnx twInstance = new Twnx(sc);
        
        configuration_setting__c configSettings= new configuration_setting__c();
        configSettings.Name='Twilio';
        configSettings.AccountSid__c = 'accountId';
        configSettings.Active__c = true;
        configSettings.AuthToken__c ='auth002';
        configSettings.Bulk_SMS__c='+18559331384';
        configSettings.Contact_Phone_Number__c='+18559172384';
        configSettings.Lead_Phone_Number__c='+14154633840';        
        insert configSettings;
        
        Test.setMock(HttpCalloutMock.class, new Twilio_MockClass());
        
        
        System.Test.startTest();
        
        Twilio.sendfromtwilio(configSettings.Contact_Phone_Number__c,'test',con.Phone);
        twInstance.sendfromtwnx();
        twInstance.ok();
        
        System.Test.stopTest();
    }
    
    //this method for testing with names as "Nexmo"
    public static testmethod void testSmsFromTwnxWithNameAsNexmo(){        
        
        Contact con = new Contact(LastName='test',Phone='+19343213321');
        insert con;
        
        ApexPages.StandardController sc = new ApexPages.StandardController(con);
        
        Twnx twInstance = new Twnx(sc);
        
        configuration_setting__c configSettings= new configuration_setting__c();
        configSettings.Name='Nexmo';
        configSettings.AccountSid__c = 'accountId';
        configSettings.Active__c = true;
        configSettings.AuthToken__c ='auth002';
        configSettings.Bulk_SMS__c='+18559331384';
        configSettings.Contact_Phone_Number__c='+18559172384';
        configSettings.Lead_Phone_Number__c='+14154633840';      
        insert configSettings; 
        
       	Test.setMock(HttpCalloutMock.class, new Nexmo_MockClass());
        
        
        System.Test.startTest();
        
        Nexmo.sendMessage( con.Phone,  configSettings.Contact_Phone_Number__c,  'text',  'sms');
        twInstance.sendfromtwnx();
        twInstance.ok();
        
        System.Test.stopTest();
    }
}

 
Xavier MametXavier Mamet
Hello,

You are not doing any assertions in you test methods to check the results at the end.
Take a look at the Apex Text Classes trailhead modules.

Xavier
Xavier MametXavier Mamet
Hello again,

if you don't know what to check in your assertions, I suggest the following:
  • set a boolean var isError to False
  • Embed your tests in a try-catch block
  • If an exception is caught, set isError to True
  • Finally, your can verify the value of isError through System.AssertEquals(False,isError) for example
kesava Mallikarjuna 10kesava Mallikarjuna 10
Hi,
you can write asserts in the Nexmo_MockClass and check for 'con.Phone','configSettings.Contact_Phone_Number__c','text sms' values in side the mock class