You need to sign in to do that
Don't have an account?
sales4ce
How to write unit tests to cover wrapper/inner class
Hi,
I am unable to figure out how i can write test methods to cover code for my wrapper/inner class.
Can any one point me in the right direction?
Thanks,
Sales4ce
That wouldn't quite work as getDtWrap returns a list of DtWrapper rather than a single instance.
Testing wrapper classes is no different to testing controllers, but you usually have to put a bit more effort in to set up the data correctly, as you are usually encapsulating lots of different information.
In this case, once you've instantiated the controller you have added an empty instance of a dtwrapper to the list, so you should be able to pull that element back and execute the methods that will give you the coverage.
Something like the following:
All Answers
You dont need to write any separate test classes for your wrapper classes. If you have written your tests well, covering most of the use cases, the wrapper classes should be called from withing your test classes. If wrapper classes are not covered, this means that you are missing some important use case and should add some more test cases.
Thanks Gulshan. I am unable to get coverage for this part of the code in "Red". Can you point me in the right direction.
Apex class:
Test Class
I have never actually done it, but in theory you should be able to do:
controller.getdtwrap().getListGroups();
I would think that that would work and call the methods that you need.
That wouldn't quite work as getDtWrap returns a list of DtWrapper rather than a single instance.
Testing wrapper classes is no different to testing controllers, but you usually have to put a bit more effort in to set up the data correctly, as you are usually encapsulating lots of different information.
In this case, once you've instantiated the controller you have added an empty instance of a dtwrapper to the list, so you should be able to pull that element back and execute the methods that will give you the coverage.
Something like the following:
Bob,
Thanks for your response. But this part of the code gives me an error in my test code.
DtWrapper candWrap=controller.getDtWrap()[0];
error message: invalid type DtWrapper.
Any pointers?
Thanks,
Sales4ce
My bad. I'm treating DtWrapper as a top level class.
Should be: