I have a question in regards to the best structure for latter testing of my code. I'm writing a test coverage code for an apex code I intend to deploy in my production. I'm up to 18% but I'm having some doubts on how to write the correct test block of code for something like this:
public void closePopup() {
displaySavedPopup = false;
}
The displaySavedPopup is declared at the beginning of the code:
public boolean displaySavedPopup {get; set;}
I can instantiate standard and extension controllers within the test coverage code, all is fine. This is the first lines of the test code:
@isTest
public class CustomObjectControllerTest {
public static testMethod void CustomObjectController(){
PageReference pagRef = Page.MyVisualForcePage;
Test.setCurrentPage(pagRef);
// Instantiate the standard controller
CustomObject__c v = new CustomObject__c();
Apexpages.StandardController sc = new Apexpages.StandardController(v);
// Instantiate the extension
CustomObjectController ext = new CustomObjectController(sc);`
Like I mentioned this looks fine and it works, the code coverage is up to 18%. Please if anyone find anything that I can improve, shoot.
So if I want to test, let's say a variable I do something like:
ext.Variable ='txt';
System.assertEquals('txt', ext.Variable);
So my question is, it is better to build my closePopup() method like this:
public void closePopup(Boolean displaySavedPopup) {
displaySavedPopup = false;
}
and not declaring public boolean displaySavedPopup {get; set;}
at the beginning of my code
than:
public void closePopup() {
displaySavedPopup = false;
}
And declaring public boolean displaySavedPopup {get; set;}
at the beginning of the code?
The issue or the second part of my question is that if I try to test closePopup() like this:
ext.displaySavedPopup = false;
ext.closePopup();
System.assertEquals(false, ext.closePopup());
I get an incorrect signature System.assertEquals(Boolean, void)
If I try this:
ext.closePopup(false);
System.assertEquals(false, ext.closePopup());
I get an incorrect signature:[CustomObjectController].closePopup(Boolean)
So, would this change on my apex code improve my testing coverage latter? :
public void closePopup(Boolean displaySavedPopup) {
displaySavedPopup = false;
}
Please let me know if I'm missing something here, that I'm sure I'm. Any tips or directions on how to improve my apex code for future testing coverage will be much appreciated.
Hope I have explain myself well, if not, let me know please.
Thanks.