You need to sign in to do that
Don't have an account?
DiutG
Need help to coverage my unit test
Hi, i want to cover my class but i don't know what i do that.
public with sharing class LCCTRL_GenBop { @AuraEnabled public static void insertFile(Id oppId, String base64FileData, Opportunity recordData) { try { Id[] contentDocIdLs = new Id[]{}; ContentDocumentLink[] ctLinkLs = [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = :oppId]; for(ContentDocumentLink ctLink : ctLinkLs) { contentDocIdLs.add(ctLink.ContentDocumentId); } ContentVersion[] cvLs = [SELECT Id FROM ContentVersion WHERE ContentDocumentId IN :contentDocIdLs AND IsLatest = true AND Type_fileupload__c = 'BOP']; String fileTitle = 'BOP--'+ (recordData.Name!=null ? recordData.Name : '') + '_V'+(cvLs.size()+1); ContentVersion cv = new ContentVersion(Type_fileupload__c = 'BOP', VersionData = EncodingUtil.base64Decode(base64FileData), Title = fileTitle, PathOnClient = fileTitle + '.' + 'pdf'); insert cv; cv = [SELECT ContentDocumentId FROM ContentVersion WHERE Id = : cv.Id]; insert new ContentDocumentLink(LinkedEntityId = oppId, ContentDocumentId = cv.ContentDocumentId); } catch (AuraHandledException e) { throw new AuraHandledException(e.getMessage()); } } @AuraEnabled public static Map<String,Object> getData(Id oppId) { Map<String,Object> dataMap = new Map<String,Object>(); Opportunity opp = [SELECT Id, Name, Customer_Selection_Criteria_Price__c, Customer_Selection_Criteria_Time__c, Customer_Selection_Criteria_Quality__c, Customer_Selection_Criteria_Location__c, Customer_Selection_Criteria_Reputation__c, Customer_Selection_Criteria_Relationship__c, Account.Name, TOLABEL(Account.Country__c), TOLABEL(Account.Type), Account.Market_cap_Investors__c, Account.Dedicated_to_therapeutic_fields__c, Account.Clinical_or_marketed_product_pipeline__c, Account.Linked_to_other_CDMO__c, Account.Cultural_fit__c, Account.Expertise__c, Account.Capacity__c, Account.Strategic__c, Account.Relationship__c, Nature_of_the_molecule__c, Z_Indication__c, TOLABEL(Stage_of_Development__c), Sales_expected_at_Peak_Sale__c, Estimated_probability_of_Success__c, When__c, Which_technology__c, First_source__c, Dead_line_to_deliver_the_offer__c, Dead_line_to_select_the_CDMO__c FROM Opportunity WHERE Id = :oppId LIMIT 1]; dataMap.put('record', opp); return dataMap; } }
I have try this to make test for enter in the method testInsertFile but he doesn't work.
In the test class is my data used in the org for test.
@isTest public with sharing class TEST_LCCTRL_GenBop { @TestSetup static void setup(){ Map<String,Schema.RecordTypeInfo> rtMapByName = Schema.SObjectType.Account.getRecordTypeInfosByName(); Schema.RecordTypeInfo recordtype = rtMapByName.get('Commercial'); Account account4Test = new Account(name = 'TEST ACCOUNT' , Country__c = 'US' , CurrencyIsoCode = 'EUR' , Type = 'Commercial' , RecordTypeId = recordtype.RecordTypeId); insert account4Test; Product2 product = TestCreate_Product2.Create_Product2(); GMID_Product__c gmid = new GMID_Product__c(); gmid.Z_Commercial_Product__c = product.Id; gmid.Z_GMID_ext_key__c = 'GMID_EXT_001'; gmid.Z_GMID_GUOM_to_KGM__c = '0'; gmid.Z_GMID_Status__c = true; gmid.Z_CRI__c = 100; insert gmid; Term_of_payment__c temOfPayment = new Term_of_payment__c(); temOfPayment.Z_EN_Description__c = 'TEST'; temOfPayment.Z_Source_date__c = Date.today(); insert temOfPayment; Opportunity opportunity = new Opportunity(); opportunity.AccountId = account4Test.Id; opportunity.Z_Product__c = product.Id; opportunity.Z_GMID_Product__c = gmid.Id; opportunity.StageName= TRGHDL_Opportunity.QUALIFICATION; opportunity.Name = 'TEST1'; opportunity.Z_Service_comments__c = 'TEST1'; opportunity.CloseDate = Date.today().addDays(30); opportunity.Z_Incoterms__c = 'CIP'; opportunity.Z_Incoterms_2__c = 'TEST'; opportunity.Z_Terms_of_Payment__c = temOfPayment.Id; insert opportunity; } @IsTest private static void testInsertFile(){ String fileData = 'Title'; String fileDateBase64 = EncodingUtil.base64Encode(Blob.valueOf(FileData)); Opportunity opportunity = [SELECT AccountId, StageName FROM Opportunity WHERE Z_Service_comments__c ='TEST1' LIMIT 1]; ContentVersion[] cvLs = [SELECT Id, ContentDocumentId FROM ContentVersion]; Test.startTest(); insert opportunity; } @IsTest private static void getData(){ } }
Try below Test Class 90% Coverage Please Mark It As Best Asnwer If It Helps
Thank You!
All Answers
Try below Test Class 90% Coverage Please Mark It As Best Asnwer If It Helps
Thank You!
Can you try the below test class. It gives you 89% test coverage.
The main issue in your test class is you are not inserting contentdocument, Lilnk and version.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Hi everyone, i appreciate all of your answer, i have marked the best answer for me after test.
All of your answer help me to understand the process to do a class test, very thanks all !