Stack Exchange Network

Stack Exchange network consists of 175 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 [unit-test]

A unit test is code that is written and executed to test a specific portion/unit of source code. Unit tests are class methods with the testMethod modifier or @isTest annotation and are usually placed in separate test classes annotated with the @isTest annotation. Code that is executed by unit tests is considered covered. At least 75% of an organization's codebase must be covered by unit tests and every trigger must have at least 1% unit test coverage.

0
votes
0answers
14 views

Please let me know how to cover this in testing? [duplicate]

for(Case_Status_History__c cs : cshMap.values()){ //CR #367 - 4 Defined SLAs //Populating the Status History with completed FirstContact milestone details System.debug('msMap = ' + msMap); ...
1
vote
2answers
33 views

How do I able to change custom setting values from test class to actual class

I found a problem that couldn't change custom setting values through test code To prevent recursive call, in the middle of context put switch code like below (trigger only runs when custom setting ...
0
votes
0answers
55 views

test class coverage for process instance

Hi I am submitting record for approval in test class, and then again I am approving it. Still the status is showing as pending. Can anyone help here? public static testMethod void ContractTestMethod()...
0
votes
0answers
20 views

Testing Inner Class [duplicate]

I have a class with an inner class: public with sharing class Response { .... public Response() {} public Response(Id testId, String testString) { ... } public class Answer { @AuraEnabled ...
1
vote
1answer
47 views

Test class Limits.getEmailInvocations() showing zero and assertion is failing

I have a bizarre issue. I have a trigger that will send an email based upon a record update. When I debug my trigger running the test class it showing the email result as success and when I debug and ...
0
votes
1answer
24 views

Test Class with wrapper [duplicate]

I have a problema with a Class test in the wrapper class.. This is mi class and doesn't have any error: public class ValeDeSalida_cls { private ApexPages.StandardController sc; public String ...
0
votes
1answer
34 views

Apex Batch runs constructor but does not execute start method

I´m trying to run a Batch to delete some 'expired' Cases. In the test method when I execute the Batch the class constructor runs but the batch start method never runs. The batch class: global class ...
1
vote
0answers
17 views

Submitting Article for Translation through Test Class causing internal error

I'm trying to test a class which queries for translations of an article. This is the setup functionality in the test class to create an article with a translation. Article_Type__kav af_1 = new ...
0
votes
2answers
40 views

How to create Operating Hours for Apex Testing

I can't really find a solution for this, but does anyone can help me with creating Operating Hours for Apex Testing? I'm not quite sure what I have to create? Only the Operating Hours - record or more?...
-1
votes
1answer
47 views

How to Cover for Loop in test Class in vf [duplicate]

I have created a test class with 44% coverage but my code is not covering the for loop part can you Please help me My Controller public class AttendanceCls{ //public List<Session__c> ...
0
votes
0answers
15 views

Test coverage for test class of trigger is showing 53 constantly [duplicate]

I am new to salesforce development.I have written test class for following trigger, which is having coverage as 53 only. I tried several times by adding and changing code lines into test class but it ...
0
votes
1answer
22 views

List has no rows while executed by system.runas()

I have a apex method which retrieves url parameters and perform SOQL and then DML operation. Here's the apex method, public void updateObjRecord(){ try{ String objId = System....
0
votes
0answers
22 views

How to test Email Services for outbound email in salesforce? [duplicate]

This is the first time I am developing Apex outbound mass email class. Could anyone help how to test the class? Here is my code: public class SendMassOutboundEmail { public static void MassOutbMail()...
-3
votes
1answer
21 views

Coverage code for remote action [duplicate]

Why the coverage code is 0? global with sharing class OutputControllerMap { @RemoteAction global static List<Output__c> findAll() { return [SELECT Id, Name, Project_Type__c,...
0
votes
1answer
28 views

Testing Queueable Class 55% now

I'm trying to test a Queueable class and I'm getting 55% only.. I tried several things but I'm still getting only 55%. This is the class: public class SherlockQueueablePolling implements Queueable, ...
-3
votes
1answer
35 views

System.QueryException: unexpected token: nullnull

I am doing a query from a field in custom settings. And updating the leads Here is my apex code public with sharing class textInputsConsecond implements Schedulable { public list<Lead> ...
0
votes
1answer
25 views

Cover a ApexPages.StandardSetController in a TestClass, help

thank you for your time, right now I'm trying to cover as the title says a standardSetController but I'm having some difficulties, the rest of the code is covered so I don't think i need to put the ...
0
votes
1answer
33 views

how to provide username and password in test method for REST API

apex.runtime.impl.ExecutionException: pad block corrupted if (req.headers.get('username') != null&&req.headers.get('password')!=null && Authorization.decrypt(req.headers.get('...
0
votes
0answers
52 views

Test Class for Dynamic SOQL [duplicate]

Pretty new with salesforce dev. So forgive me. I am doing a SOQL query and then updating records. The trick here is . I am grabbing my query from two custom fields which are in the Custom Settings . ...
0
votes
0answers
75 views

LWC: Getting error while testing with validity object using lwc-jest

I am trying to write test case on my blur event(using lwc-jest), which is working fine, till I am not adding my custom validation method: setValidity in my component, which getting called on blur and ...
2
votes
1answer
55 views

Can I use test.loadData() with more than 10K records?

I'm writing a component to handle CampaignMembers, and it will be common to have more than 10k CampaignMembers. So I'm writing my SOQL to get the campaignMembers in batches of 10K, appending them to ...
0
votes
1answer
25 views

Email not been sent from the finish method of a batch job in a unit test

The below code is to validate if an email has been sent from the finish method of a batch job using the Limits.getEmailInvocations(). The afterEmail variable is been set to 0 and no email is been sent ...
3
votes
2answers
121 views

How is it possible for @TestSetup to effect test result?

While refactoring a test to make it more consistent with the style of our other tests, a colleague came upon something really weird. The original test created the test account in @TestSetup, like so: ...
0
votes
0answers
10 views

Using EvenRelation with Event to assign multiple owners - Test class issues

I have a batch job that counts a bunch of different objects owned/assigned to our Sales Users. One criteria for counting Events is that I need to count Events Owned/Assigned to the user AND Events ...
0
votes
1answer
65 views

What is the life-cycle of static properties in Apex classes?

Sometimes when developing Apex, I've populated some static property. But then later -- most often in an Async or Test context -- I go to access it again and discover SFDC is behaving like it is ...
-3
votes
1answer
49 views

JSON Expected '[' at the beginning of List/Set IN Test class [closed]

I am facing below error in test class: Malformed JSON: Expected '[' at the beginning of List/Set Error will throw in below line of the controller: warpList =( List<CaseAssociatedSerExc>)...
1
vote
1answer
31 views

LTS and sfdx/developer orgs

I was reviewing the capabilities of the LTS (lightning testing service) and there is a cool sentence in the documentation: Lightning Testing Service can only run in scratch orgs, because tests can ...
1
vote
0answers
24 views

How add a ServiceReport to a test class [duplicate]

trigger ServiceReporttoSA on ServiceReport (after insert) { for (ServiceReport SR: Trigger.new) { ServiceAppointment SA = [select Id FROM ServiceAppointment WHERE ID =:SR.parentId];...
2
votes
1answer
26 views

Is the Trial-Phase relaxing Test-enforcing and ToolingAPI to save APEX on Production Orgs?

As a great surprise I have noticed today at the org of a new client (his Org is running in the Trial-phase) that APEX Tests seems not to be enforced and that I could modify and save APEX quickly using ...
0
votes
0answers
26 views

Test class for pagereference in a method [duplicate]

I am unable to get code coverage for my pagreference, my code is code: public class selectedcase { public list<recordtype> record {get; set;} public id ids; public selectedcase(){ ...
0
votes
0answers
30 views

Test class for RequestData class [duplicate]

@HttpPost global static List<HHSurvey> getHHSurveyList() { RestRequest req = RestContext.request; RequestData mRequestData = (RequestData)JSON.deserialize(req.requestBody.toString()...
-1
votes
1answer
52 views

Send email failed, No body supplied for file attachment in a batch apex [duplicate]

I wrote a batch apex to send reports. PFB the main class and test class but not able get the code coverage. Please assist me. public class BatchReportsAutoSend implements database.Batchable<...
0
votes
1answer
20 views

Trouble writing Help Class for JSON de

This test class is driving me crazy. I have can prove an array is passing through the class from the test class, but I can't seem to get code coverage. I did use the Json2Apex tool to build the class. ...
5
votes
1answer
106 views

Any way to use sfdx force:apex:test:report to poll?

To work around another problem (EAI_AGAIN errors when pushing or running unit tests in a newly created scratch org from Jenkins CI using SFDX), I'd like to (gently) poll for the test results produced ...
1
vote
1answer
83 views

Test Class for Controller Extension Visual Force Page

I am trying to test my controller extension, Although the final score coverage hit into 100% but when i checked my tests log in my dev console i got Error. This is the ERROR Message: System....
0
votes
2answers
51 views

Test method for request in JSON Format

Malformed JSON: Expected '{' at the beginning of object @HttpPost global static Void doPost() { //Initailizing variables String respString =''; ...
4
votes
1answer
48 views

Are Apex tests run differently depending on how they are started?

So I have this test Class, when I run the test from inside Salesforce it fails. When I run the test from the Dev Console it passes. Why are the results different when I invoke the test from a ...
1
vote
1answer
30 views

Test Class for the below code

i have written a test class for the following code, but it throwing a error like "Attempt to dereference a null object". can anyone please help me to overcome this. public class leadclass { ...
0
votes
1answer
38 views

Code Coverage - Salesforce Connect Custom Adapter / Datasource.Connection Class

I am unable to find documentation on or get any code coverage for the customer adapter Apex Class (Datasource.Connection Class). For awareness, the external data source and customer adapter functions ...
1
vote
1answer
68 views

Creating Test Class for Einstein Bot Invocable Apex Class to Search Articles

I've created an Invocable Apex Class that allow us to search articles and return the resolution to the bot. The Apex class works as expected in the sandbox. However, I'm struggling to create a test ...
3
votes
1answer
29 views

How can I set the data for a report testing?

I have a schedulable class that runs a report and send an email with the results of that report. Everything works fine when I'm testing it with the report filled with data, but when the report is ...
1
vote
0answers
14 views

Having trouble accessing updated Contact.Histories in unit test [duplicate]

I have a custom object to manage patient (Contact) status changes, which affect product shipments. I'm adding a process to roll back changes based on receiving a cancelled form, based on a common ...
2
votes
1answer
87 views

Can't update record in test method

I'm trying to make a test class for an Apex class that runs a report and add functionality for it (send some emails and stuff). The problem is that I need to add records (contacts) for that report to ...
0
votes
1answer
33 views

Apex Unit Testing List<Case>

I have a method public static List<Case> findCase (Id recordId) that returns List<Case> details. I wrote the following Test and it passed. List<Case> details = ...
0
votes
1answer
35 views

Test Class Issue Standard set Controller Class

I write a test class to cover standard set controller class on account but i am not able to pass id. thats why not able cover code coverage. here is my code @IsTest public class ...
0
votes
1answer
31 views

need help on writing test class for controller

i have controller for vf page, i have written a test class. test class is having two methods where i am succesfully able to run the test for Autocal but for Save method i am getting following error ...
1
vote
1answer
23 views

Tests passing with zero code coverage [duplicate]

It seems like literally every test I write is passing with zero code coverage org wide. I've spent the past 2 days on and off reading forums, doing trails and debugging. Below is an example of one of ...
-1
votes
1answer
38 views

Test CLass code coverage problem

trigger Updaterelatedoppty on Account ( after update,after insert , before insert,before update ) { //before trigger if(Trigger.isbefore ) { for(Account acct :Trigger.new){ ...
0
votes
1answer
33 views

Is there a better way to create related records when creating test data?

I am trying to create a large set of test data along with child records and this is what i came up with. Could anyone let me know if there's a better way to achieve the same? Integer countStart = ...
1
vote
0answers
45 views

Create Knowledge article with channels in apex test code

We have a use case where we expose knowledge articles to customer community users and I'm trying to write test code for that. The problem I am having is that whenever I query for articles using ...