You need to sign in to do that
Don't have an account?
inbox outbox 7
Can anyone help me with the test class? I could not cover the wrapper class variables in the test class
Below is the code:
Test class doesn't cover the bold part of the code.
Test class doesn't cover the bold part of the code.
@httpGet global static accountWrapper accountInformation(){ RestRequest req= Restcontext.request; // String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1); String requestURI= req.requestURI; String accountId= requestURI.substringAfterLast('/'); List<Account> accList= [SELECT ID, Name, Rating, Description, Industry, Phone, Fax FROM Account WHERE ID =: accountId]; List<Contact> conList= [SELECT ID, Name, FirstName, LastName, Email, Phone FROM Contact WHERE accountId IN: accList ]; List<Case> caseList= [SELECT Id, CaseNumber, Subject, Description, Status, Owner.Name FROM Case WHERE accountId IN: accList]; accountWrapper wrapper= new accountWrapper(); if(!accList.isEmpty()){ wrapper.accountRecord= accList.get(0); wrapper.conList= conList; wrapper.caseList= caseList; } return wrapper; } global class accountWrapper{ global Account accountRecord; global List<Contact> conList; global List<Case> caseList; }Test class:
@isTest public static void deleteAccountTest(){ String recordId= createTestRecord(); String url= '/services/apexrest/v1/Account'+recordId; RestRequest req= New RestRequest(); req.httpMethod= 'DELETE'; req.requestURI= url; RestContext.request= req; try{ Test.startTest(); AccountManager.deleteAccount( ); Test.stopTest(); }catch(system.Exception ex){ system.assertNotEquals(null, ex.getMessage()); } } static Id createTestRecord(){ Account testAcc= New Account(); testAcc.Name= 'testAccount'; INSERT testAcc; Contact testCon= New Contact(); testCon.LastName= 'test contact'; testCon.AccountId= testAcc.Id; INSERT testCon; return testAcc.Id; }
https://salesforce.stackexchange.com/questions/244788/how-do-i-write-an-apex-unit-test
https://salesforce.stackexchange.com/questions/244794/how-do-i-increase-my-code-coverage-or-why-cant-i-cover-these-lines
Thanks!
All Answers
Try Below Class Please Mark It As Best Answer If it Helps
Thank You!
Please Close your Query By Marking It As Best Answer So It Also Helps Other In Future
My apoligies, I put the wrong test class (httpDelete). Thank you so much for replying.
I put the correct code below for the httpGet.
Class which is not completely covered. Again, my apologies.
Bold part is not covered.
Thank You!
It is httpGet method not delete, also code coverage did not change. My reason for putting this questions is to get full code coverage. My test class works fine, it is just that I wanted to get the full code coverage but the code you have mentioned did not increase the code coverage.
Again my apoligies for not putting the correct code in the beginning.
I would like to get more input on this.
Thank you @CharuDutt.
https://salesforce.stackexchange.com/questions/244788/how-do-i-write-an-apex-unit-test
https://salesforce.stackexchange.com/questions/244794/how-do-i-increase-my-code-coverage-or-why-cant-i-cover-these-lines
Thanks!