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
Kam.ax1015Kam.ax1015 

REST controller - Apex test Code Coverage

Hello,

 

I have like 10 REST controllers with GET/PUT/POST methods. Are there any samples of Apex unit tests? I need to be able to upload this app so somehow I need to get to 75% mark .

 

Any help will be greatly appreciated.

 

Thanks,

Kam

dkadordkador

Here's an example:

@RestResource(urlMapping='/someMapping')
global class MyResource {

    @HttpGet
    global static String echoString(RestRequest req, RestResponse res, String x) {
        return x;
    }

    static testmethod void testEchoString() {
        String input = 'abc';
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
        String output = MyResource.echoString(req, res, input);
        System.assertTrue(input == x);
    }

}

This is from memory so there may be syntax issues.

 

Note that in the pilot we do not support packaging, so you'll be unable to upload any package that contains an apex REST class. 

Kam.ax1015Kam.ax1015

Hello,

 

Thanks for your help. I will try it out. Hopefully it will be work for POST/PUT/DELETE

 

Thanks,

Kam

Stuart_KimbleStuart_Kimble

Do you know when the pilot is due to end and apex REST classes will be supported in packaging?

dkadordkador

The GA date is not yet available.