ApexSensei

Drills Unit testing

Mock an HTTP callout

Tests cannot make real HTTP callouts.

Your task

Finish the mock so the provided HTTP client can be tested with no network, and make your own test register it.

@IsTest
public class AS_0199CD2979A4_Mock implements HttpCalloutMock {
    public Integer statusCode = 200;
    public String body = '{"ok":true}';

    public HttpResponse respond(HttpRequest req) {
        return null;
    }

    @IsTest
    public static void fetchesOkBody() {
        String result = AS_0199CD2979A4_Client.fetchStatus();
        Assert.areEqual('{"ok":true}', result);
    }
}

Requirements

  1. returnsOkBody should pass
  2. throwsOnServerError should pass
  3. respondUsesItsFields should pass
  4. learnerTestRegistersTheMock should pass

Sign in to open this drill