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.

Filter by
Sorted by
Tagged with
0
votes
0answers
9 views

Issue in Test class code coverage

Apex Class: public without sharing class Communities_ListingBroker{ public List<MRIS_Application__c> applications { get; set; } public Map<String,String> officeIds { get; set; } ...
0
votes
0answers
14 views

How UserInfo.getUserId() can return null? [duplicate]

I need return null for UserInfo.getUserId() for testing. How can I do that?
0
votes
1answer
18 views

System.UnexpectedException: No more than one executeBatch can be called from within a test method

I have Added Limit to the Query and in Test Class @isTest(SeeAllData=false), if(!Test.isRunningTest()) -Every Solution I found Here .Even it's not working here .So please any one can Help? Apex Class ...
0
votes
1answer
31 views

Unable to Insert ContentVersion record as a Community User in Test Class

I'm unable to create ContentVersion records running a test class as a Partner Community user. I have created a Partner user using the same methods displaying in the test class, tested the process ...
-1
votes
1answer
27 views

How to write Test class for the below [duplicate]

Apex class: public class ProdImedComAr { public class Respuesta { public Integer Codigo; public String Descripcion; public Long NroOperacion; public String ...
0
votes
0answers
11 views

LWC tests without Salesforce DX project structure

Is there any way to test LightingWebComponent in the salesforce project which doesn't has a DX project structure? In the documentation we can see that sfdx-lwc-jest works in Salesforce DX projects ...
-4
votes
0answers
40 views

I need to cover all exception in my Apex test class [on hold]

Test class static testMethod void testbuildPatientReferrals(){ System.runAs(UserTest.createMCMAdminUser()) { TestUtilities.IS_FMA_ENABLED = true; Test.startTest(); ...
0
votes
1answer
20 views

All Required Permissions to Create ModifyAllData PermissionSet

I have a class where I check if the User has ModifyAllData permission: SELECT PermissionSet.PermissionsModifyAllData FROM PermissionSetAssignment WHERE AssigneeId = :UserInfo.getUserId() AND ...
0
votes
0answers
8 views

Is it possible to populate ServiceAppointmentHistory in tests? [duplicate]

I'm working on an application that has an HTTP endpoint where clients should be able to get the history of the Status for a ServiceAppointment. This history is available in the ...
0
votes
1answer
14 views

TestMethod Doesn't Support Web Service Call Out Error For Trigger on delete

I have this trigger which deletes the Specific Objects records on delation of a record. I wrote a test class for this but since I am a toootal Noob, I was unable to manage to cover the whole thing and ...
-2
votes
0answers
11 views

How to i get coverage for this methods [duplicate]

Could you help me on getting test method coverage: public static String insertarLog(String strInterfaz, String strSolicitud) { Logs_Interfaces__c objLog = new Logs_Interfaces__c(); objLog....
0
votes
1answer
23 views

Test class data created before 'runAs' user not visible

My test class sets up a Community User and some data prior to doing a runAs the new user. In the runAs section I call a controller which requires the use of the data I created earlier, but it doesn't ...
0
votes
2answers
41 views

How do I create a Community User in apex code?

I need to create a test class for a community user, so need to first create the user, then do my test as that user. I'm struggling to get the Account for the User though. What is wrong here? The last ...
-2
votes
0answers
24 views

How to call a class method with a list parameter from Apex unit class [duplicate]

How can I write a unit test for the below trigger? trigger triggers_for_sites on Site__c (after insert, after update) { if((trigger.isinsert||trigger.isupdate)&&trigger.isafter){ ...
0
votes
1answer
46 views

How to use SeeAllData = True method inside a test class with SeeAllData = False

I have written a test class where I need to insert Survey Invitation record, for which Survey required (i.e. Survey is parent and Survey invitation is child). I'm querying the Survey record since ...
0
votes
1answer
74 views

Test Case - Attempt to de-reference a null object (Formula Field)

Now I have 0% coverage. System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CaseHandlerCountAlert: execution of AfterInsert caused by:...
0
votes
1answer
37 views

Error attempting to create test data in @TestSetup

This Trigger sends an email alert when an Account creates 8 cases within a 7 day period. If any of 3 specific fields is equal to 'LIVE - CLOSED PROJECT' the email is sent to a Global Email address. ...
-6
votes
0answers
25 views

need test class For below code [duplicate]

this trigger update the all child records amount in Account Object when after:insert,update,delete,undelete..i dont know how to write test class Trigger: trigger SubscriptionTrigger on ...
-1
votes
1answer
22 views

How to call this method from web service in my test class [duplicate]

I am not able to call this method in my test class: WebServiceCallout.invoke( this, request_x, response_map_x, new String[]{endpoint_x, 'https://www....
-2
votes
2answers
20 views

I am not getting test class coverage [duplicate]

i have written a class i am trying get test coverage. i have written below. Could you please help me here Class : public class WrapperCam { public Boolean check{get;set;} public Campaign ...
1
vote
1answer
55 views

Apex debug logs change trigger execution, makes addError(String) either throw or not throw exception

I have a fresh case of strange Apex behavior that is throwing me for an absolute loop. I have a trigger on after insert and after update that needs to cycle through some records. It will update ...
0
votes
1answer
29 views

Apex Test class code coverage [duplicate]

Not getting coverage on these line of code, can anyone help with the test class? @AuraEnabled public static Boolean deleteRecord(Id recordId){ Sobject sobj = recordId.getSObjectType().newSObject(...
0
votes
1answer
23 views

Apex Test coverage on External Objects

How can the Test Coverage can be fulfilled for the Apex classes which queried for External Objects.I have written Test class just like assuming External Object behaves like a custom Object but getting ...
0
votes
1answer
97 views

ShowToastEvent is not working for jest test class

MyLighingwebcomponent <template> <lightning-card title="Custom Search Functionality in LWC" icon-name="standard:account"> <div class="slds-m-around_medium"> &...
0
votes
1answer
23 views

Deployment of destructive changes to production and tests execution

We need to remove trigger and apex test class for it from production org. We've already put together destructiveChanges.xml and are going to deploy it to prod org via ant migration tool. The question ...
0
votes
1answer
17 views

Static method cannot be referenced from a non static context - Test Class

I'm trying to write a test class for this class but not sure how to provide code coverage for what I'm doing here. In my class I'm just running a query, looping through the query and creating a list ...
0
votes
2answers
51 views

My apex class code coverage is showing zero percentage on writing the test class

Apex class: public class GenRangoTarjeta_cls {// OJCB v 1.4 This class generates a range of cards concatenating the program code and country code public static void addRangoTarjeta (...
-1
votes
1answer
27 views

Error: Compile Error: Invalid bind expression type of Schema.SObjectField for column of type Id at line 10 column 46

@isTest public class SharinPixWorkOrderTriggerTest { @isTest public static void testSharinPixWorkOrderTrigger() { WorkOrder fieldVisit = new WorkOrder(Job_Name__c='Visiting Green ...
0
votes
1answer
23 views

Test Class For FinishURL StandartsetController

I have an APEX class that ends with a finishURL method; this class is the controller-extension of a VF page. What they all do is to collect the IDs of the selected items on a related list view, then ...
0
votes
0answers
26 views

system runAs method to verify if the user can access a record

I have below test class which verifies whether a use have access to the record or not. The Campaign__C object's sharing setting is Private. However with below test class when I run the SOQL the 2nd ...
-1
votes
0answers
11 views

Code coverage of trigger is not increasing [duplicate]

trigger ProductTrigger on Product2 (before insert, before update) { list lstServiceId= new list(); decimal strYr; if(Open_Enrollment_Details__c.getinstance('OpenEnrollmentYear')!=null) strYr=...
1
vote
1answer
41 views

Test method fails with “Attempt to de-reference a null object” but code in class runs

I'm getting System.NullPointerException: Attempt to de-reference a null object when I run the test class, but the batch class will run without any issue. Here is my batch class: global class ...
-2
votes
1answer
36 views

Test class fails to call the method

can someone help me to find the cause why my test class doesnt cover the method that is called in the test class, as seen in my test class I create an instance to call the method from the class. But ...
0
votes
1answer
16 views

In test class can see all org users in list

I have written one query in test class for fetching users,as per my understanding query should return the user records created in test class only,but its giving all user from salesforce org.is that ...
0
votes
1answer
26 views

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ContactTrigger: execution of BeforeUpdate

I am getting the following error in my test class. The insert tests work fine but the update test is failing. Error: 20:02:22:421 FATAL_ERROR System.ListException: List index out of bounds: -1 20:02:...
-3
votes
0answers
15 views

How to test below code in test class? [duplicate]

public class PS_DEXOutArrayOfExternalSystemReference { public List<PS_DEXOutExternalSystemReference> externalSystemReferenceList; }
0
votes
1answer
29 views

Trigger Testing Issue

Im just fleshing out the logic here before tiding it up. For the life of me I cannot figure out why this isn't working. The Primary__c is being changed in the trigger but it is not asserting that is ...
1
vote
0answers
28 views

Callout Exception when testing

I use a webservice to validate government info on companies. This is used for accounts and Cases. For some reason I'm getting this calloutException but there's no DML before the callout. I'm getting ...
0
votes
1answer
27 views

Apex: Use one test class in another test class

I am working on some email automation and I have a separate test class for each language, kind of like this: @isTest public class EnglishEmailTest { @isTest public static void test1() { .....
4
votes
1answer
93 views

Mocking CurrentPageReference wire in Jest unit tests - LWC

I have a LWC component which uses CurrentPageReference from lightning/navigation bundle in a @wire function. I am using lwc-jest to create unit tests for my components. Using the wire with ...
1
vote
0answers
18 views

How to test whether a Platform Event Trigger throws an unhandled exception

Since platform event triggers are run asynchronously, an error in processing them doesn't cause the test method to fail by itself. So, how would I write a test that under certain circumstances, my ...
0
votes
2answers
24 views

Unable to access versionData from test class

I am facing an issue but I don't know what I'm doing wrong. I'm writing a test class for a code which has this 2 lines: public static Blob getPkpass(){ // more code here... List<...
0
votes
0answers
18 views

How do you create Resource Calendar in Apex for test class?

I need to have a Resource Calendar in Apex test class. I tried to do below in Test Class. List<Calendar> lc = new List<Calendar>(); for(Account acc :listAcc) Calendar c =...
0
votes
0answers
8 views

UI Theme Detection: Unit test code coverage

Since Winter '16, we have had the ability to add conditional logic to our Apex controllers and Visualforce pages based on the UI theme the user is currently working with (i.e. Classic vs. Lightning ...
1
vote
3answers
43 views

How to cover Catch block in ApexUnitTest class when using DML statement in try body

I have some apex code, where I try to upsert a list of records: try { upsert recordList Accounts; } catch (DmlException e) { //do a loooot of stuff in order to provide a proper ...
1
vote
1answer
35 views

How to test an inner class?

I did my research, but could not find a clear guidelines on how to test an inner class. This is my inner class: public class ExistingAccountResult{ public String salesforceaccountid {get;set;} ...
-2
votes
1answer
36 views

how to write a test class for web service HttpPost

I'm new to development here I'm developing a webservice in rest and I have no idea about how to write a test class for that. Please find the below code of apex class: @RestResource(urlMapping='/...
0
votes
1answer
34 views

Creating test class for apex (reports namespace) used in Flow action

I have a Flow which calls an apex class (via action). The purpose of the action is to grab a list of Lead Id's from a specific report. The reportID is passed to the class from the flow. Then, the ...
0
votes
0answers
16 views

Need Help with a test class to my apex class that attaches a Visualforce Page pdf to the quote [duplicate]

I found a way to write an apex class that attaches my quote which is generated by an vf page as a pdf to my quote object. Writing the test class is even a bigger problem for me. I get to 36% coverage ...
0
votes
1answer
23 views

ContentSize in Test Class

I am writing a trigger that deletes files/attachments smaller than 5 KB assigned to email messages. I read on this post that the field ContentSize on ContentDocumentVersion is not writable. My ...