Writing the test class for an Extension in Apex
When we need to write test cases for an extension that might be a bit of a learning curve and this post helps you with that.
When we need to extend the functionality of the a Visualforce page the option that we reach out to is Extension in Apex.
Extension are super duper useful in extending the capabilities of a Visualforce.
If the ask from business is to fetch a single record and display the fields we reach out to Standard Controllers.
Also, standard controller has access to 9 methods that we can straight off use without worrying about anything else.
Now what if we have to add a custom method on top of it?
That’s when extensions will come into picture.
But the catch is how do we write the test class for Extensions?
Extensions will have one argument constructor and it becomes tricky.
This is how we write the test class for extensions.
Hope this helps!