I have a utility class which is mostly instance variables.

public with sharing class JSON2ApexLead {
public cls_data[] data;
public String account_id;   //CL07e1BB74
public String client;   //testsalesforce
public String scope;    //salesforce
public Integer expires; //1411501687
class cls_data {
    public String customId;   //RB0e620324
    public String Country;  //USA
    public String PostalCode;   //94107
    public String State;    //CA
    public String City; //San Francisco
    public String Street;   //350 Main Street
    public String Title;    //Analyst
    public String Industry; //Marketing
    public String NumberofEmployees;    //10-25
    public String Company;  //Co Name
    public String LastName; //Smith
    public String FirstName;    //John

followed by a few class methods. How can I get coverage on those lines which are just variable declarations?

  • 1
    You must use them in your unit test, instantiate the class, assign values to them. If you can't think of any possibility then the next question will be, do you need them ? – Mihai Neagoe Feb 14 '15 at 20:37

The proper unit test for this class on its own is to test that an instance can be created and to assert that the values are what they should be directly after creation. This will result in your instance variables being covered.

static void testConstructedState() {
    JSON2ApexLead inst = new JSON2ApexLead();

    System.assertEquals(null, inst.client);
    System.assertEquals(null, inst.scope);
    // similar asserts for all other instance variables...

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.