You need to sign in to do that
Don't have an account?
Cameron Houser
Test Class for Twilio SMS and Voice, Help Needed!
I have working Code the sends an SMS or Voice call via Apex and Twilio, Great stuff. The trouble I am having is writing the Tests (maybe because its Friday?) and I just need a little help. I don't do near enough Apex for my liking and I am feeling it here.
I know I should be writing a Http mock someplace in my test...Any help/pointers would be most appreciated.
Working SMS:
Working Voice:
Test Class:
I am getting 0 error messages, and 0 test coverage
I know I should be writing a Http mock someplace in my test...Any help/pointers would be most appreciated.
Working SMS:
public class TwilioSMSInvocable { @InvocableMethod public static void callPhoneService(List<ID> caseIDs) { List<Twilio_SMS__c> SelectTwilio_SMS = [Select Id, MobileNumber__C, Message__c from Twilio_SMS__c Where ID in :caseIDs] ; for (Twilio_SMS__c t : SelectTwilio_SMS){ Map<String,String> params = new Map<String,String> { 'To' => t.MobileNumber__c, 'From' => '13176666666', 'Body' => t.Message__c }; DoCallout(params); } } @future(callout=true) private static void DoCallout(Map<String, String> params){ String account = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; String token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; TwilioRestClient client = new TwilioRestClient(account, token); TwilioSMS sms = client.getAccount().getSMSMessages().create(params); System.Debug('TwilioSMS ' + sms) ; } }
Working Voice:
public class TwilioCallInvocable { @InvocableMethod public static void callPhoneService(List<ID> caseIDs) { List<Twilio_Voice__c> SelectTwilio_Voice = [Select Id, Say__c, URL_Build__c from Twilio_Voice__c Where ID in :caseIDs] ; for (Twilio_Voice__c t : SelectTwilio_Voice){ Map<String,String> params = new Map<String,String> { 'To' => t.MobileNumber__c, 'From' => '+13176666666', 'Url' => t.URL_Build__c }; DoCallout(params); } } @future(callout=true) private static void DoCallout(Map<String, String> params){ String account = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; String token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; TwilioRestClient client = new TwilioRestClient(account, token); TwilioCall call = client.getAccount().getCalls().create(params); system.debug('TwilioCAL' + call); } }
Test Class:
@isTest private class TwilioSMSTest { static testmethod void testTwilioSMSInvocable() { Map<String,String> params = new Map<String,String> { 'To' => '+17602444355', 'From' => '13176664444', 'Body' => 'test message' }; String account = 'AC6a217d8adb3460b5870c05bc6c666666'; String token = '397c3f614cd3cf783154dc2383234444'; TwilioRestClient client = new TwilioRestClient(account, token); TwilioSMS sms = client.getAccount().getSMSMessages().create(params); test.startTest(); Test.setMock(HttpCalloutMock.class, new TwilioSMSTest()); test.stopTest(); } }
I am getting 0 error messages, and 0 test coverage
Rewriting just the section between startTest and stopTest: Do the same for the other class, in a separate test method. This could be in the same test class.
Hope this helps.
Kindly mark this as solved if it's resolved.
Thanks,
Nagendra
What am I doing wrong?