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?

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
  • 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 Oct 15 at 12:57
  • I also added new : OuterClass.ExistingAccountResult result = new OuterClass.ExistingAccountResult(); , but same error – Ivo Dimov Oct 15 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 Oct 15 at 13:02
  • 1
    which error? I assume your inner class has an explicit constructor(s)? If so, add a default non-private constructor . – Oleh Berehovskyi Oct 15 at 13:02
  • Got it. I had a type as well. It is working now. Thanks – Ivo Dimov Oct 15 at 13:02

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.