You need to sign in to do that
Don't have an account?
Test class cannot access inner class from Controller
I have the following controller that contains a simple inner class. My original test methods where in the
controller but as my test code began to grow I decided to move it to their own class.
My test class is throwing the following error: Invalid type: MyProduct
I know that that I can move MyProduct to its own class but that is not the point. How does my test class
access this inner class?
public class MyController {
public class MyProduct {
public String name {get;set;}
public String code {get;set;}
}
public List<MyProduct> products {
get {
List<MyProduct> theProducts = new List<MyProduct>();
// do something here to fill the list with MyProducts
return theProducts;
}
set;
}
// more code that may or may not be important
}
@isTest
private class MyControllerTest {
private static testmethod void testMe() {
MyController myCon = new MyController();
List<MyProduct> testProduction = myCon.products; <--- throws error
}
}
Thanks
Jeff Douglas
Informa Plc
http://blog.jeffdouglas.com
Give this change to your test method a shot:
MyController myCon = new MyController(); List<MyController.MyProduct> testProduction = myCon.products;
Does this work?
@isTest private class MyControllerTest { private static testmethod void testMe() { MyController myCon = new MyController();
//I added the dot notation to access the inner class
List<MyController.MyProduct> testProduction = myCon.products; } }
OK.. thanks for the help but I found the main problem... I'm an idiot <g>. I had tried the same thing (MyController.MyProduct) and after saving the file noticed the same error. My only problem was that the error was being thrown from A DIFFERENT line and I didn't notice it.
Thanks!
Jeff Douglas
Informa Plc
http://blog.jeffdouglas.com