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
10 views

How write test class to update account address to contact address [duplicate]

I am trying to write apex test class for updating account address to contact address. Trigger: trigger UpdateContactAddTrigger on Account (after insert) { UpdateContactAddresses addr = new ...
0
votes
0answers
16 views

How to write Test Method [duplicate]

I am learning test methods.I wrote a trigger for contact address with account address after insert with apex class. My code: public class UpdateContactAddress { public Contact contactSO; ...
-2
votes
1answer
33 views

Test class has an runtime error

Test class throw the runtime error System.AuraHandledException: Script-thrown exception public with sharing class LWCExampleController { @AuraEnabled public static void deleteRawData(...
0
votes
1answer
17 views

How to test a batch that executes based on CaseHistory records?

I have written a batch class that updates a field on Case object with the owner name which is assigned by Case assignment rule. When I try to test this batch class, a part of the code which runs after ...
0
votes
0answers
37 views

Apex Test Class generator [closed]

I am planning to build a utility to generate TestClasses based on Sample data selected. Example, An Account Id with specific list of fields should generate a code with creation of Account with test ...
0
votes
0answers
24 views

is there a way to run a duplicate job in unit test? [closed]

I need to run a duplicate job in a unit test is there any way to do that?
0
votes
0answers
26 views

How to do unittest on EOF

I am trying to write a unittest for !EOF but don get how to adres this do I need to add a /n to the string since I do not get how to get in the loop. Apex integer lineNr = 1; while (!reader....
0
votes
0answers
25 views

Test class for batch class passed success but 0% code coverage

Can anyone help me here as to why i am getting code coverage as 0% even though my test class is running successfully? The scenario is that i am fetching all the Frozen users from the UserLogin object ...
0
votes
1answer
28 views

Unit tests for Apex Trigger Handler using a framework

I am using Kevin O'Hara's TriggerHandler framework in my new Trigger. I couldn't understand how to unit test the TriggerHandler. Here's the sample code from the Github repo. Trigger code: trigger ...
0
votes
0answers
18 views

Error while rejecting approval request in test class

Explanation: I wanted to cover the following lines of code: for (ProcessInstance pi : [SELECT TargetObjectId, ( SELECT Id, StepStatus, ...
0
votes
0answers
32 views

Help with cover test coverage for content document [duplicate]

public class EmailJob implements Queueable { public static Boolean doChainJob = true; private Date toDate; public static string emailTemplateName = 'Report Template'; public EmailJob(Date ...
2
votes
0answers
32 views

Updating the Case MasterRecordId field in Apex tests

I have currently got a bit of code running in my beforeUpdate trigger that updates 4 fields of a case once the MasterRecordId field is changed. This is because that field is used to distinguish ...
0
votes
1answer
41 views
+50

Implementing test class for Queueable Apex that makes call outs

I have a Queueable class MyQueueableClass which in turns calls an outbound web service class. public void execute(QueueableContext qc){ try{ GlobalCallout.makeCallout(caseId); } catch (...
0
votes
1answer
40 views

Error in Test class for uploading a CSV through Visualforce

public class importDataFromCSVController { public static blob csvFile{get;set;} public static String csvAsString{get;set;} public static string[] csvFileLines{get;set;} public static ...
1
vote
1answer
26 views

Unit testing Schedulable that calls future method

This has been asked here and here, but I'm not satisfied with the answers. Hoping to gain a better understanding of this. In working through the Apex Specialist Superbadge, the callout portion of the ...
0
votes
0answers
19 views

How to write test class in decimal number to words? [duplicate]

how to write the Apex test class for decimal numbers to words? how to code coverage in class public String getNumberTOWord(Decimal num) { Decimal junkVal = num; Decimal junkValPaisa = ...
0
votes
1answer
25 views

Apex Specialist Superbadge Step 4 - Cover Map line [duplicate]

I'm having trouble to get 100% coverage on that trigger, the line that is not getting covered is that: "casesToEvaluate.put(maintenance.Id, maintenance);" Here is my trigger: trigger ...
0
votes
0answers
15 views

How to cover my handler class in a test class [duplicate]

public class CaseTriggerHandler { public static void closeCase(Set<Id> caseId,Map<Id,Case> newMap){ List<Quality_Investigation__c> qualityInvestigationList =...
0
votes
0answers
28 views

Can someone tell a TEST for this [duplicate]

I have written this APEX class to use as a controller on a VFP. I need to write a TEST class for this. Can someone help with the test class for the below code ? Thank-you (The use case is to auto ...
0
votes
0answers
13 views

Create Survey for Test

I have a batch class that takes survey invitations and sends reminders for the ones without any responses after a certain number of days. Now, I am trying to write a test class for it. And while ...
0
votes
0answers
20 views

Created User unable to update opportunity stage due to error: insufficient_access_on_cross_reference_entity

I am writing a test class in which I have created user with profile =finance and role =finance.I used System.runAs(createdUser) to update opportunity stage.But getting following error ...... ...
4
votes
2answers
123 views

Param is unnamed__0 if StubProvider used on interface (instead class)

I am unable to use the System.StubProvider to mock/stub a complicated Backend class of which I have no implementation but only an interface public interface ShopBackend { void initialize(); ...
2
votes
1answer
23 views

Does tests in unlocked packages execute when deploying unpackaged apex code to production?

I'm sorry for the cryptic title. I'm curious what tests are forced to run when deploying to production, if that production org contains unlocked packages. Lets say we have the following test classes ...
1
vote
0answers
26 views

Code coverage for AuraHandledException in catch blcok

public with sharing class ContactCtrl { @AuraEnabled public static List<AccountContactRelation> getRelatedContacts(String accId){ List<AccountContactRelation> result = New ...
0
votes
1answer
41 views

Code coverage for for loop [duplicate]

I have inserted a List of case records with proper values but still, code is not covering as shown above. Can anyone please suggest to me?
0
votes
0answers
14 views

Add Prospects to a Sales Cadence Automatically with Process Builder and Apex

In the documentation Salesforce provided the apex code. But I need to write an apex class that covers the code. I couldn't find anything similar in web. Does anyone have an idea or documentation that ...
-3
votes
1answer
22 views

How to write Test Class in apex [duplicate]

Can any one help me to write test class for below mentioned code trigger ContactTriggerWithList1 on Contact (before insert) { List<Account> lacc = [select Id, Name, Type from Account]; for(...
0
votes
1answer
21 views

A/B Test Send Log [closed]

what is the steps to implement a send log for A/B test send? I have not found anything on the documentation
0
votes
1answer
42 views

list has more than 1 row for assignment to sobject error in test class

Below is my test class method: static testMethod void test_createCaseWithPPAs_UseCase1(){ List<Post_Record__c> post_record_Obj = [SELECT Id from Post_Record__c]; System.assertEquals(...
0
votes
1answer
13 views

Constructor not defined and Type not visible error

I have a apex class which has a sub class and a constructor. below is the apex code public static final List<String> alphabetArr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''); private class ...
1
vote
2answers
192 views

npm command not found when working with jest in LWC

I am doing this trailhead module to get started with testing in LWC. The first step is to run below command sfdx force:lightning:lwc:test:setup But when I run this in terminal, I am getting a below ...
-1
votes
0answers
22 views

Test class for the apex class [duplicate]

Here is the apex code. I am looking for test class: public class LeadUpdatedTriggerHandler { Set accountCompanyMatches = new Set(); public void handleBeforUpdate() { Set leadEmails = new Set(); Set ...
1
vote
1answer
10 views

Testmethod PermissionSet Assignment has no effect on FLS checks

Use case - verifying that running user's permissions permit custom field to be created. Assume that: PermissionSet myPermSet grants edit permission on Obj__c.Fld__c The test's running user does not ...
0
votes
1answer
15 views

Is it possible to use another name for the TestDataFactory class

I have followed the trailheads for making a TestDataFactory. In the documentation it states that the TestDataFactory is a special class used for testdata. What isn't clear to me is can I change the ...
0
votes
1answer
28 views

How to write test class for below controller? [duplicate]

public class Invoice { string ids; private final Invoice_Master__c Invo; public List ListItems {get; set;} public Invoice(ApexPages.StandardController Controller){ Invoice_Master__c Invo1 = (...
2
votes
0answers
31 views

UNABLE_TO_LOCK_ROW error while running salesforce apex test on circleci

I'm getting UNABLE_TO_LOCK_ROW while running the apex test on CircleCI How can I avoid the deadlock while running tests?This is due to parallel execution of test(Not sure about this). Do We have ...
0
votes
1answer
23 views

Apex test class can't have Production profile in Scratch Org

I have a test class like this: Account acc = new Account(name='testAcc'); Insert acc; Contact con = new Contact(LastName='TestContact', AccountId=acc.Id); Insert con; Id p = [...
0
votes
0answers
7 views

test class for a flow which updates the lookup filed on custom object based on the value of another field [duplicate]

I need help to write a test class for a flow which updates the lookup filed on custom object based on the value of another field on the same object. I have a custom object named Bank__c with lookup ...
2
votes
1answer
23 views

In an unit test for an LWC, how can I prove a method executes periodically according to metadata configuration?

I have the following HTML: <template> <h1>Current price of a bitcoin in Euro</h1> <lightning-formatted-number currency-code="EUR" ...
1
vote
1answer
44 views

In an unit test for an LWC, how can I prove an async chain is setting a value in a lightning-formatted-number?

I am trying to prove that the price is being set on the component. I have the following HTML: <template> <h1>Current price of a bitcoin in Euro</h1> <lightning-formatted-...
1
vote
1answer
28 views

In an unit test for an LWC, how can I mock out a fetch to a third party API?

I have a Lightning Web Component with the following HTML: <template> <h1>Current price of a bitcoin in Euro</h1> <lightning-formatted-number currency-code="EUR"...
2
votes
2answers
76 views

Salesforce automated testing techniques [closed]

I am a Salesforce QA tester and as all my testing has been manual up to this point, I am interested to learn how to automate some of the new upcoming features and possibly existing processes on ...
0
votes
1answer
45 views

How do I call this method inside of inner class

Hello im really confused about how to call requestBody(Id quoteId) inside this code I created using inner classes: public class PT_Interface{ public class Request_Model { public ...
0
votes
1answer
25 views

error is comming for befortrigger my gestcaselist is coming empty what i need to change in my test class

public class PSAResourceRequestHandler_CLS extends BaseTriggerHandler_CLS{ public static List < PSA_Resource_Request__c > psaResourceRequestLst = (List < ...
0
votes
2answers
19 views

Apex Test Class Error on FinancialForce Sales Order Object

I've been trying for a few days to get this to work and but I've run out of ideas. I'm stuck. I can't get this test class to work. I get the following error. Trigger trigger efs_Sales_OrderTrigger on ...
0
votes
0answers
28 views

SOQL EventRelation is Test Class

The issue with SOQL on EventRelation filtered by Relation.Type is working as expected during normal execution. However, while executing the following LOC in test class it causes failure. Code: List<...
0
votes
1answer
58 views

Apex test coverage for custom metadata type [duplicate]

Question: How can a unit test cover the throw exception part? List<abc__mdt> settings = [ SELECT DeveloperName, Value__c FROM Setting__mdt WHERE ...
0
votes
0answers
28 views

Possible to keep (or equivalent of) a public static variable across test classes in an async test run?

I have test methods I want to use from test class A in test class B, in an async test run if test A runs before Test B I don't want to invoke the test A methods in test B because they already ran and ...
2
votes
1answer
52 views

LWC Testing framework

We have a really nasty problem with the LWC Jest tests. Every single test takes too much time to execute on Windows. For example, the very same tests take 5 secs to execute on Mac and over 1 minute on ...
1
vote
1answer
24 views

Does “helper methods” ((not marked as @IsTest)) in test methods are counted into lines of test coverage?

I mean if in order to test some method I will write another method (not marked as @IsTest) then it will decrease test coverage? So, in this example: @isTest private static void deleteDuplicatesTest()...

1
2 3 4 5
80