0

I have a class which has a method with a parameter of JSON type. Now my goal is to create a Test class to test the method with the parameter of JSON. Please see my codes.

This is my method in my myClass:

public static void createAccount(CT_Part result){
  System.debug(result.record);
}

Here is my Test Class method:

@isTest static void createAccountTest(){

}

This are my sample Data JSON which I will use to test the method from my test class.

{'record':{'sourceSystemIdentifier':'System Administrator',
                    'sourceProcessIdentifier':null,
                    'initiatorAuthenticationLevel':'NA',
                    'correlationId':'sample',
                    'requestorId':'sample',
                    'requestorRole':'sample'}}

How will I test my method using the sample JSON data.

0

If I understood well, you have to deserialize your sample data into you object (using Json.Deserialize method), and then call your test function as usual

cf : https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_System_Json.htm#apex_class_System_Json

1
  • Thank you very much, that's it all I need is the keyword :) thanks for helping me Apr 12 '19 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.