0

I have created test class for apex class in my developer account.

1) Create a global test class which implements HttpCalloutMock

@isTest
global class WebServiceCalloutExampleCalloutMock implements HttpCalloutMock{  
global HttpResponse respond(HTTPRequest req){
    HttpResponse res = new HttpResponse();
    res.setStatus('OK');
    res.setStatusCode(200);
    res.setBody('GREAT');
    return res;
}
}

2) Test Class for your Apex Class

@isTest
private class WebServiceCalloutAccount_Test {  
static Account getTestAccount(){
    Account myAcc = new Account(Name = 'Test');
    insert myAcc;
    return myAcc;
}

private static testMethod void callFutureMethod() {        
    Account a = getTestAccount();

    Test.startTest();
    Test.setMock(HttpCalloutMock.class, new     WebServiceCalloutExampleCalloutMock());
    WebServiceCallout.sendNotification(a.Id);    
    Test.stopTest();

}
}

3) Actual apex class

public class WebServiceCallout {
@future (callout=true)
public static void sendNotification(String id) {
    Http http = new Http();
    HttpRequest req= new HttpRequest();
    HttpResponse res = new HttpResponse();
    req.setEndpoint('https://***********/****.php');
    req.setMethod('POST');
    req.setBody('id='+EncodingUtil.urlEncode(id, 'UTF-8'));
    HttpResponse response = http.send(req);
    req.setCompressed(true);
}
}

When I run test for "WebServiceCalloutAccount_Test" (point 2) it gives result : Tests method passed and code coverage for "WebServiceCallout" (point 3) is 100% which shown in developer console.

Then I tried to deploy apex class "WebServiceCallout" (point 3) using eclipse to my production organisation it gives warning "0% coverage" and not deployed.

Can anyone say me what is the problem?

5
  • Did you try to deploy code coverage as well?
    – kurunve
    Commented Feb 9, 2017 at 11:50
  • No I tried to deploy only apex class Commented Feb 9, 2017 at 11:52
  • How can I deploy code coverage? Commented Feb 9, 2017 at 11:53
  • 3
    You have to select all three files at once, right-click, choose Deploy To Server, and enter your production credentials. If you do this right, it should deploy okay.
    – sfdcfox
    Commented Feb 9, 2017 at 11:54
  • 2
    Side note: req.setCompressed should be before http.send(req).
    – sfdcfox
    Commented Feb 9, 2017 at 11:54

0

You must log in to answer this question.

Browse other questions tagged .