1

I did my research, but could not find a clear guidelines on how to test an inner class. This is my inner class:

public class ExistingAccountResult{
    public String salesforceaccountid {get;set;}
    public String status {get;set;}
    public Boolean includeinfunnel {get;set;}
    public String masterid {get;set;}
    public string accountid{get;set;}        
}

How do I call it from my test class?

1 Answer 1

4

Simply create an instance of inner class and populate its properties by test data:

OuterClass.ExistingAccountResult result = new OuterClass.ExistingAccountResult();
result.salesforceaccountid = // testId
result.status = // testStatus 
result.includeinfunnel = // testData
result.masterid = // testId
result.accountid = // testId
7
  • That is what I thought as well, but getting errors. I tried: OuterClass.ExistingAccountResult result = OuterClass.ExistingAccountResult(); but getting Invalid Type OuterClass.ExistingAccountResult
    – Ivo Dimov
    Commented Oct 15, 2019 at 12:57
  • I also added new : OuterClass.ExistingAccountResult result = new OuterClass.ExistingAccountResult(); , but same error
    – Ivo Dimov
    Commented Oct 15, 2019 at 13:01
  • 1
    @IvoDimov I am sure your outer class is not named as OuterClass. Use the exact name of the class that wraps your inner class.
    – Jayant Das
    Commented Oct 15, 2019 at 13:02
  • 1
    which error? I assume your inner class has an explicit constructor(s)? If so, add a default non-private constructor . Commented Oct 15, 2019 at 13:02
  • Got it. I had a type as well. It is working now. Thanks
    – Ivo Dimov
    Commented Oct 15, 2019 at 13:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .