function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Siana DcruzSiana Dcruz 

How to write test class for inner class?!

Hi all,
I have a test class something like this.

global class Maincontroller()
{
  global virtual class summary extends summary1
  {
    global virtual override void startPage()
    {    
    //Lines of code
    }
  }
}

Can anyone please tell me how to cover the startPage method in my test class.Since this method is inside the inner class, I have no idea how to write the test class for that.Any help would be greatly appreciated.
Rupal KumarRupal Kumar
Hi,

Try this -
 MaincontrollerObject emp = new MaincontrollerObject (Name = 'Test', Age__c = 12);

Maincontroller.summary Incls= new Maincontroller.summary(emp);
Incls.startPage();
related Link-http://www.infallibletechie.com/2014/07/how-to-cover-inner-class-in-test-class.html



Thanks 
Rupal kumar
http://mirketa.com
 
Ajay K DubediAjay K Dubedi
Hi,
Firstly correct your code, a class never have any braces.
Following code will be helpful to cover inner class:
MaincontrollerObject controllerObj = new MaincontrollerObject();
Maincontroller.summary innCls= new Maincontroller.summary();
innCls.startPage();

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi