@isTest
public class AttachmentRestriction_Test{
// Test Method to cover try block
public static testMethod void TestMethod1(){
// Created account record for parent id to attachment
Account acc = new Account();
acc.Name = 'TestAcc';
insert acc;
Attachment att = new Attachment();
att.Name = "TestAtt.txt";
att.Body = "test body";
att.parentId = acc.Id;
insert att;
// created object of the class
AttachmentRestriction testObj = new AttachmentRestriction();
testObj.attRestriction(att);
}
// this methos to throw error and cover catch block
public static testMethod void TestMethod2(){
AttachmentUploadController testObj = new AttachmentUploadController();
Attachment att = new Attachment();
testObj.attRestriction(att);
}
}
Please mark this answer as SOLVED and BEST ANSWER if it helps you.
May I suggest you to please check the Test generator App From app Exchange.
- https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3A00000EFozgUAD
Please check the below link to Best Practice in Test classes.- http://amitsalesforce.blogspot.sg/2015/06/best-practice-for-test-classes-sample.html
- https://help.salesforce.com/articleView?id=000041398&type=1
Hope it helps.Please mark it as best answer if the information is informative.
Thanks
Rahul Kumar
You can try following test class.
Please mark this answer as SOLVED and BEST ANSWER if it helps you.
Regards,
Yogesh More
Salesforce consultant || Salesforce Developer
more.yogesh422@gmail.com || yogeshsfdc11@gmail.com
www.yogeshmore.com || Skype:-yogesh.more44