You need to sign in to do that
Don't have an account?
Tatiana Cooke 9
Test Class not touching my Code
Team,
Pretty new to the development side of things and need help on the following class. It a class with a visualforce page (Button) that adds attachements to the notes and attachements section and refreshes to the parent page when ckick save.
For some reason the test class is not running my class and achieving any code coverage.
Appreciate any help.
Below is the test class:
Test class:
Pretty new to the development side of things and need help on the following class. It a class with a visualforce page (Button) that adds attachements to the notes and attachements section and refreshes to the parent page when ckick save.
For some reason the test class is not running my class and achieving any code coverage.
Appreciate any help.
Below is the test class:
public class attachmentsample { public attachmentsample(ApexPages.StandardController controller) { } Public Attachment myfile; Public Attachment getmyfile() { myfile = new Attachment(); return myfile; } Public Pagereference Save() { String accid = System.currentPagereference().getParameters().get('id'); Attachment a = new Attachment(parentId = accid, name=myfile.name, body = myfile.body); /* insert the attachment */ insert a; return NULL; } }
Test class:
@isTest public class Test2attachmentsample { private static testMethod void attachmentsampletest() { Tenant_Coordination__C TC = new Tenant_Coordination__C(Name ='Test'); insert TC; Attachment attach=new Attachment(); attach.Name='Unit Test Attachment'; Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body'); attach.body=bodyBlob; attach.parentId=TC.id; insert attach; List<Attachment> attachments=[select id, name from Attachment where parent.id=: TC.Id]; System.assertEquals(1, attachments.size()); } }
All Answers
In test class you have pass parameters to the visualforce page
Getting the following error when entering your code. Error: Compile Error: line breaks not allowed in string literals at line 8 column -1.
Any thoughts?
Regards,
TC
I was able to fix the above issue by changingApexPages.currentPage().getParameters().put('id, TC.id); to ApexPages.currentPage().getParameters().put('id', TC.id);
However I am still not getting any code coverage.
I noticed in the above code I used PageReference ref = Page.yourpagename; which in reality my visualforce page should be "Attach Invoice"
Even after updating both the above I still have Code Coverage 0% (0/9) on my attachment sample class.
Any thoughts?
Thank you!! #happygal
I do not know the initial requirement for functionality with visualforce.
Yeh Jose, I agree with you instead of over riding button with visualforce page we can create a URL button and send id with the URL (So we can get rid of StandardController) :) ;)