Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [code-coverage]

Questions about specific lines of code that need coverage or platform bugs. 75% of your Apex code must be covered by test classes. This tag is not intended for use when code coverage is simply lacking, but for scenarios where because of a particular configuration or system issue code coverage is challenging.

0
votes
0answers
21 views

Hello i am not able to get the result from this test class [duplicate]

I am trying to update the email in my Test class but it is not happening please help me. This is my class- global class PrepareSandboxPostCopy_Batch implements Database.Batchable { String query; ...
0
votes
2answers
51 views

Test Class - Error - Constructor not defined

Error - Constructor not defined: [PrepareSandboxPostCopy_Batch].() Test Class @isTest private class SandboxPostRefreshTestCase { static Testmethod void testSandboxPostCopyScript() { ...
-1
votes
0answers
17 views

Test class for Httpget method [duplicate]

I am struggling to write a test class for below, can some help on this? @RestResource(urlMapping='/CaseAccountid/*') global with sharing class CaseAccountid{ @HttpGet global static List<Case&...
-1
votes
0answers
27 views

Can anyone help me in this test class [closed]

I was straggling in this test class from last 6 days and now i have done this but i am confuse is it right or wrong can anyone help me in this This is my apex class--- global class ...
0
votes
1answer
22 views

How to test the current logged in user in test class?

I need to cover the below method where I am using the current logged in user in the query. @Auraenabled public static User getUserInformation() { User user1 = new User(); user1 = [...
0
votes
1answer
24 views

Custom Controller Test Coverage

Having a bit of difficulty getting any code coverage for my custom controller. The goal of the controller is to display a list of opportunities in a list where the division of the user is the same as ...
0
votes
1answer
16 views

Unable to get code coverage for while traversing from parent to child in a SOQL query

In the following test class I am getting only 20% code coverage, and I am able to track it up to some level. Actually I am getting 100% code coverage before adding the following AND condition to the ...
-2
votes
0answers
27 views

Test Class for Apex Trigger: Need help to write a test class for the following Trigger: [duplicate]

I am new to Apex and don't have much experience with test classes. Can anybody please suggest as to how to cover this trigger? Which points should I keep in mind or share a sample code which can help ...
2
votes
0answers
41 views

Unit test for apex class that queued and execute unit tests of the org

I have 2 apex class for automated unit test execution, basically this 2 classes : Here I already made the test class for the first apex class (AutomatedTestJobQueuer) like that : @isTest static ...
-1
votes
0answers
24 views

Not able to cover this class. help [duplicate]

Can anyone please take a look at my test class and figure out why the class is not getting covered. i am stuck on 27 % Here is the trigger: trigger checkActiveContacts on Contact (before insert,after ...
7
votes
1answer
89 views

How do I increase my code coverage, or why can't I cover these lines?

This is a canonical question and answer developed by the community to help address common questions. If you've been directed here, or your question has been closed as a duplicate, please look through ...
0
votes
1answer
41 views

Getting to 100 percent code coverage on my trailhead module “Write Negative Tests Unit”

I seem to be stuck on this trailhead module or write negative tests unit, while I have 93 percent code coverage, I can't seem to get the code coverage to hit 100 percent at the "returnValue" piece ...
0
votes
1answer
22 views

How to test Exceptions (Query and DML) for ContentDocument?

I try to write wrong query, but I get just error un my test, not coverage. If I use try-catch in unit-test - no error and no coverage either. How to test it right? And how can I test here delete DML ...
0
votes
2answers
30 views

Code Coverage low even though I'm calling the method

I am coding an Apex Test Class for an Apex Class. I am have trouble understanding why some lines of code are being covered while others are not. I also don't understand why the if statement in my ...
6
votes
2answers
192 views

Is this test for callout wrong? How to make a bulk?

I wrote mock and test for callout, but I don't think it's right. I think I check wrong things with asserts and maybe call the same methods a few times, while have another ways to get 100%. Have I? I ...
1
vote
1answer
43 views

Batch Test Class works in Production, Fails in Test

I've started a new job and the test code coverage here is poor. I am working to improve this and one of the batch classes has coverage of 77% in production. This is now below the org % so I thought I'...
-2
votes
1answer
34 views

Cover execute method of a Batch class

first of all thank you for your time, i need some help to cover this batch class, right now the test class i will post bellow only covers the finish method and the get; set; . CLASS: global class ...
0
votes
1answer
17 views

Test Class for Visualforce Controller Test Class Coverage

I have a simple Visualforce page with a simple controller as follows public class EDU_CustomController_Getter { private String sortOrder = 'LastName'; //This is the getter method used to parse ...
2
votes
1answer
41 views

Need help to cover {get; set;} methods on a TestClass

i need some help on a TestClass as i said above, bellow i wil show you what the class looks like and the TestClass: APEX CLASS: public with sharing class DirectDebitController { public class ...
-2
votes
2answers
91 views

Problem In covering Account Team Member

Followed Approaches: Approach1: I have created test users and Tried it,but still account team member isnot covering Approach2: If I tried for currently Logged in user below issue is present ...
1
vote
2answers
67 views

How to get code coverage on formula fields in a wrapper class

I need to get code coverage on UpgradeRate, PlusCount2, PremiumCount2 and PrestigeCount2, but what I have is not working. How do I get code coverage on these? In my custom controller, I have the ...
4
votes
2answers
135 views

Test Coverage for ENUM, Properties - Differences with default value, no values, and getters/setters

Maybe I am remembering wrong but I think things have changed and I missed the document. Back to basics with this question For a class that has no methods and is just ENUMS: public class muENUMS{ //...
1
vote
1answer
35 views

Insufficient Code Coverage for Batch Class

global class EmailNotificationBatch implements Database.batchable<sObject>,Schedulable,Database.Stateful { /* Getting data from the account */ global Database.QueryLocator start(...
0
votes
1answer
32 views

Test Coverage for Pattern Matcher in Apex

I have the below code in my controller Class in a Verify () function - public class SA_reCAPTCHA { private Reference__c Reference; public List<Reference__c> RefID = new List <...
-3
votes
1answer
19 views

Test class example for Push Topic [closed]

I am unable to get 95-100% test coverage for below class here is my class global class BT_Invoicing_New_Override_Crtl { public ApexPages.StandardController stdCon; public BT_Invoicing__c ...
-1
votes
0answers
38 views

How to test for wrapper class and aggregate results array

I have a custom controller with some wrapper classes and I'm unsure how to write a test class for the wrapper classes. I'm also unsure how to get code coverage for an array of aggregate results. Right ...
0
votes
2answers
31 views

Test Coverage for Custom Error Logging

I created a custom object to store errors in my code. So I am updating some of my classes to take advantage of this object, but I am now running into issues with test coverage. I am taking advantage ...
0
votes
1answer
71 views

Test class for method with API call and return type String

How do we write test method for Apex class used by Lightning component where my return type of method is String but within the method I call rest api Here is my class method: public static String ...
1
vote
1answer
25 views

How to increase code coverage for catch block

I have below Apex class (DAO class) which has a try-catch block. Same try-catch block has been used in 5 different methods. I tried sending setOpportunityId as account id or null id but still, it is ...
-2
votes
1answer
31 views

How to create ApexClass record in test class?

Here are many objects on which DML are not allowed in test class. But if our code is querying ApexClass sObject then how can we create some ApexClass records in test class to cover our code?
1
vote
1answer
189 views

Clearing or resetting a singleton in test class

I'm writing a test method to reset the value of a singleton variable, however I have no clue how to do it. please can someone assist me with the test code to test the following: public class Service ...
0
votes
1answer
20 views

Test class for Vf page controller failing

I've two vf pages QRCase (output) and QRCaseEdit(input/Edit) which are used to create cases for a specific record type 'Quality Report Case'. I tried writing the test class for controller, but it's ...
0
votes
0answers
20 views

I want to deactivate trigger in production via xml-file. Will it count against the code coverage at the time of deployment? [duplicate]

I want to deactivate trigger in production via xml-file. Will it count against the code coverage at the time of deployment? We are rolling out new trigger and deactivating the old one. We want it to ...
1
vote
1answer
59 views

Methods defined as TestMethod do not support Web service callouts - Unit Test [duplicate]

We have a custom object called 'support' - we have process builder configured for this object. in one of the process builder action it will invoke Apex (Invocable Method). This will trigger a callout ...
-1
votes
1answer
45 views

Test Class/Method for TriggerHandler - Negative scenario

For this class below, which essentially counts the number of Open cases on an Account, on update/insert/delete of a Case, can anyone help me write/provide a scenario of a test method that can hit the ...
-1
votes
1answer
37 views

Need help with a Test class coverage

Hello guys i need help to cover this Trigger on a Test Class, this Test Class also covers another class so some Data is not refering to the Trigger. This is the Test Class: @isTest private class ...
1
vote
1answer
82 views

deployment using change set- run specified test

Hi i have a changeset which has 2 apex class and their test classes with 65% and 80% individually test coverage, if i choose a option of run specified test, will that be deployed? Because one of apex ...
1
vote
2answers
70 views

setting RecordType in Test Coverage

I am having trouble on a test that is setting a record type. I believe I am setting the record type the correct way, the test is passing, but my test coverage is telling me that no record type was set....
0
votes
1answer
170 views

Social Sign On for Salesforce Reg Handler Class and Test Class-System.NullPointerException: Attempt to de-reference a null object

My org is setting up social sign on with Google and I am running into an error I have never seen before: System.NullPointerException: Attempt to de-reference a null object Does anyone know a ...
0
votes
1answer
34 views

Test Class Not Covering Original Class

So I am trying to cover this Chatter Answers Class so I can increase my system's code coverage. The test class runs successfully but the original class is still 0% covered. What do I need to do to ...
0
votes
0answers
73 views

Not covering batch execute method querying CampaignMember

AccountActivityUpdateBatch class execute method is not covering the for loop. Here is my test class. @istest public class AccountActivityUpdateBatchTest { @testSetup static void setup() { ...
2
votes
2answers
42 views

Code coverage annotation for or statement next line or same line?

Ik have a class with several or statements. To make the code more readable I placed the or statements on a next line. My dev console shows that there is no coverage for these lines. Do I need to place ...
-3
votes
1answer
33 views

Unable to cover apex Test class

Apex Class public class get_data{ public static map<string,map<String,String>> get_tier(String fetchFrom){ map<string,map<String,String>> dataFields = new map<...
0
votes
1answer
102 views

System Assert Exception in Test class of Case Trigger

We have a very old Case trigger which has a condition for a particular record type if the Task is open then case close should not close the case, Now the business user want to lift that restriction, ...
2
votes
3answers
82 views

Test for Apex class that creates a custom field

I have an apex class that creates a custom field on an sObject via an HttpRequest and I'm not sure how to write a test for this because one of the things I need to test is that the field has the ...
0
votes
1answer
30 views

Test Class for testing controller twice

I have a test class below that is successful and covers accessing my controller with a callout: @isTest static void testUpdateOfPack(){ MockPackageService mockRes = new MockPackageService(); ...
-1
votes
1answer
40 views

Code coverage for wrapper class is 0% [closed]

I have written below Wrapper class. global class BI_VA_AutomationWrapper { global class BI_VA_AutomationRequest { webservice String userName; webservice String emailId; webservice ...
1
vote
2answers
369 views

Code coverage error when deploying to another sandbox, but Salesforce doesn't show which classes are missing coverage

As the title says, I'm trying to deploy some code and metadata from a sandbox to another. The deployment compiles successfully, and the tests pass too, but the deployment fails with the "Code coverage ...
0
votes
1answer
38 views

Cover inside for - test class

I tried to get the coverage inside the for.. this is the code : and this is my test class : Profile profileId = [SELECT Id FROM Profile WHERE Name = 'Manager CS' LIMIT 1]; User usr = new User(...
0
votes
1answer
68 views

Code Coverage Error While Deploying

I want to deploy some of my classes (which are above 83% each) from sandbox to production. But it is showing code coverage error while deploying through change set. There are other classes without ...