You need to sign in to do that
Don't have an account?
Laytro80
Testing Coverage Help
Hi,
Am still a newbie on APEX and testing scripts. The APEX code itself works exactly right. The Testing script contained is successful with 0% coverage.
What the controller does
We have an object called meeting note, and an object called attendee. Attendee appears as a related list on a new meeting note. When a user clicks new a visualforce page loads with a very simple input form. When the user hits save they are returned back to the meeting note note the saved attendee record.
Any pointers / help on the test script would be much appreciated.
public class attendeeExt { Attendee__c attendee; public attendeeExt(ApexPages.StandardController ctlr){ this.attendee = (Attendee__c)ctlr.getRecord(); } public Attendee__c getAttendee(){ if(attendee == null) attendee = new Attendee__c(); return attendee; } public PageReference Save(){ try{ insert attendee; } catch(DmlException ex){ ApexPages.addMessages(ex); } PageReference pr = new PageReference('/'+attendee.Meeting_Note__c); pr.setRedirect(True); return pr; } public static testMethod void testattendeeExt() { Contact c = new Contact(FirstName='Test', LastName='Contact'); insert c; Meeting_Note__c m = new Meeting_Note__c(Subject__c='Test'); insert m; Attendee__c a = new Attendee__c(Meeting_Note__c = m.id, Contact__c = c.id); insert a; System.assertEquals(c.id,a.contact__c); } }
Thanks
Ross
Hi Ross,
Why cant the get method be called in test method? Actually in action, this method is automatically called by VF when the page loads. We can simulate it here. Hence we need to address it manually for test coverage purpose. Below might be the unit test code.
All Answers
Thanks for this I get an error.
Sorry spotted the error the a variable was being used twice.
Thanks for your help.
Need to get increased code coverage. I currently have 73%. The lines highlight in red seem to be the problem.
Thanks,
Still only getting 73% test coverage line 37 was added I had to change a to a different variable.
Why dont you remove the assertion and then run test... let me know which lines were not covered
Thanks for all your help I removed line
The problem lines are:
Hi,
Sorry to ask, but did you have any other suggestions?
Thanks
Ross
Hi Ross,
Why cant the get method be called in test method? Actually in action, this method is automatically called by VF when the page loads. We can simulate it here. Hence we need to address it manually for test coverage purpose. Below might be the unit test code.
Thanks so much I did not realise you needed to manually test the get method.
Much appreciated.
Kind regards
Ross
Thanks for all your help Srini