1

I have a DTO class where lots of inncer classes are defined like..if i am wiring

public OuterClass{
 innerClass1{
//variables declarations

}
 innerClass2{
//variables declarations

}
...
...
 innerClassn{
//variables declarations

}



}

Following Class is not able cover anything. Please suggest easiest way

@isTest
public class OuterClassTest {



    @isTest static void myUnitTest() {
        Test.starttest();

        Outerclass.innerclass1 innerClass1= new Outerclass.innerclass1();
        Outerclass.innerclass2 innerClass2= new Outerclass.innerclass2();
        ......
       Outerclass.innerclassn innerClassn= new Outerclass.innerclassn(); 


        Test.stopTest();

    }
}
2
  • How many lines is it saying are uncovered. If it says 0% of 0 lines you should be fine.
    – Eric
    Nov 7, 2016 at 1:26
  • one of 540 lines Nov 7, 2016 at 2:20

1 Answer 1

4

You either have to access each property or add a constructor:

For example

public class outerClass{

    public class innerClass{

         public string aProperty;

    }


}

To test the above you would:

OuterClass.innerClass c = New outerClass.innerClass();
c.aProperty = 'my value';

OR

public class outerClass{

    public class innerClass{

         public string aProperty;

         public innerClass(){}

    }


}

To test the above you would:

OuterClass.innerClass c = New outerClass.innerClass();

Some related information:

Unable to cover get set in apex test class

How to test Data Structure Classes?

Additionally, I believe a class with no methods and only properties does not count toward coverage. If it says 0% or 0 lines you are good. I do not recall the complete ramifications though so I would personally just set the values

You must log in to answer this question.

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