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
-5
votes
0answers
28 views

How to write a test class for this class [closed]

/* * @Author: CEPTES Software Pvt. Ltd. * @Group: Dialer * @Test Class: CloudConnectCallbackTest * @Description: Rest resource for callback */ @RestResource(urlMapping='/callback/v1/*') global class ...
0
votes
1answer
32 views

Validation Rule is failing tests on Stage, but not on Dev or Prod -- everything appears to be the same across all 3

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Due Date is a Required Field: [Due_Date__c] Stack Trace: Class.TestDataFactory....
-2
votes
0answers
24 views

how can I write a test class for this code? [closed]

public with sharing class RentedBike { //public integer times; //public decimal decHours; // public decimal netprice; public Decimal custPrice {get;set;} public customer__c custinfo ...
-2
votes
0answers
19 views

How to write a test class for a picklist (Salesforce) [duplicate]

I have this following picklist class for which I am trying to make a test class but I' stuck //Método picklist Origem do Lead public List<SelectOption> getOptions(){ //...
3
votes
1answer
78 views

How to get code coverage report for LWC unit tests with JEST?

I was working on the unit test setup for Lightning Web Components with Jest and tried to figure out how to get a code coverage report but found nothing in the Docs. By running: sfdx-lwc-jest --...
0
votes
0answers
20 views

How to cover ConsentEvent platform event trigger in test class

I have written a trigger on Standard platform event object 'ConsentEvent' which gets fired whenever user or contact email is updated. But I am not able to write test class for the same. I have tried ...
-2
votes
0answers
33 views

How does a soql get covered in test class in a simple get method

I have an apex method which simply gets the record when passed with an Id. I have pasted the Apex and its test class.When I run the test class it covers just the method entry line and not the query ...
0
votes
1answer
11 views

Enterprise Territory Management (OppTerrAssignDefaultLogicFilter) Test Class Error

I am in the process of implementing the territories within Salesforce and was following the instructions and sample code from the help documents here: https://developer.salesforce.com/docs/atlas.en-us....
0
votes
0answers
14 views

Issue in approval process in apex

I have a trigger which send email every time an approver on quote is changed. I know that it is possible to do with a help of approval process notification, but I have to add CC to email and with ...
0
votes
2answers
40 views

Code Coverage for Catch block in test class?

I'm unable to cover the code coverage for catch block.Kindly help me to cover that code lines as well. Apex Class: public without sharing class ZTS_EU_Contact_populateCallDates { Map <id, ...
-1
votes
0answers
10 views

Test Unit Salesforce [duplicate]

Just want an idea on how will i create Test Unit for this scenario Classes for the Scenario Class CallOutAPI - Call Out External API Class CallOutAPI_Test - Test Unit for CallOut API using HTTP Mock ...
0
votes
1answer
21 views

Apex Test Class failing - cannot figure it out - Webcall out [duplicate]

I am trying to use an Apex Class I found at this link: https://automationchampion.com/2020/12/01/getting-started-with-process-builder-part-50-auto-convert-leads/ Here is the Apex Class: Public class ...
-2
votes
0answers
19 views

When i am execute my test class in cpq its shows an error FIELD_CUSTOM_VALIDATION_EXCEPTION: Price Book Not set to an order?

please help me to slove this issue im hard stop in this one @isTest public class Test_Conensus_Tier_UpgradeController { @testSetup static void setup() { Account acc = new Account(); ...
-1
votes
0answers
17 views

Classt Testing with catch exceptions [duplicate]

I already create a test class, but I think is too simpple, and my cover is 44% public class PortalProveedoresController { public boolean displayPopup {get; set;} public string idprov{get;set;} public ...
-3
votes
1answer
47 views

Test Class for an existing Apex Class

Apex Class public class DistanceRecord { public class FlowInputs { @invocableVariable public String AccountId; } @InvocableMethod public static void getAcct(List<FlowInputs&...
0
votes
1answer
35 views

Why do I NOT get an Owner.IsActive field when I Query Lead in my trigger (When Testing)?

In short: my Test Setup Method Creates Accounts/Contacts/Leads/Campaign/etc I connect all of this data in my Test Setup method. I update the data in my Test Method. I query the Contacts and Leads, ...
1
vote
3answers
72 views

@testSetup best practice

I'm trying to understand something so I can use @testSetup annotation wisely. As i read here: https://developer.salesforce.com/docs/atlas.en-us.202.0.apexcode.meta/apexcode/...
-3
votes
1answer
29 views

Creating Test Class for @RestResource with helper class [duplicate]

Test Class that I am trying to write - @isTest public class TC_RetrieveProfileFromCareerBuilder_test { static testmethod void getMethod(){ RestRequest request = new RestRequest(); ...
0
votes
1answer
88 views

Test Class Coverage for Trigger with oldMap

I have an Apex Trigger and Handler class on the Business Process object. When a lookup field (Financial_Planner__c) is updated on the Business Process, the system should query all Tasks associated to ...
-4
votes
1answer
36 views

Test class for setters & getters in virtual class [closed]

How to write test class to cover setters and getters in virtual class. Please help to get code coverage for the below class public virtual class TriggerHandlerExtension { public List<String&...
0
votes
2answers
26 views

Mocking BusinessHours records returns System.MathException: null

I am stuck on a test method and any help would be highly appreciated. To provide some context: I created a method that queries a specific BusinessHours record on the DB and validates if a Case was ...
1
vote
1answer
24 views

Batchable class which publishes events... test assert not working?

I have a batchable class which updates a record, then publishes an event. To write a test which ensures the "publish" occurs, I've created a fake instance of the class which normally ...
0
votes
1answer
17 views

Apex Unit Test for Rest Resource calls wrong class

I have 2 RestResource classes: @RestResource(urlMapping='/Catcher/*') global Without Sharing class vecCatcher { @HttpGet global static void httpGet() { ... } } and @RestResource(...
3
votes
1answer
54 views

Flaky apex tests fail unreproducible with UNABLE_TO_LOCK_ROW when inserting Product2

Recently, our tests started to fail randomly with the dreaded UNABLE_TO_LOCK_ROW. The only fix seems to "Restart on Failed" the pipeline until it succeeds. This is the fixture code in ...
1
vote
1answer
25 views

How do you populate a parent value in a test class

I have a custom object, "Opportunity Contact" that is a junction between Opportunity and Contact. In my LWC I'm creating records and it works alright. Now I'm building the test class and hit ...
0
votes
1answer
39 views

Error: Opportunity must have a primary quote in order to create an order.: [] - SBQQ CPQ Test class

I am very new to CPQ, and I am given a test class to write directly. When I try creating order in my test class, I am getting this error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Opportunity must have a ...
0
votes
0answers
14 views

Unable to Create Test User : MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object [duplicate]

I am trying to write an unit test to create a test user. I get the above error upon insert. Any ideas, workarounds or suggestions. Following is a sample of the test method. This only seems to happen ...
0
votes
1answer
27 views

How do I fix my error with test?

I need to cover some new functionality with tests, and for this I need to convert the lead in the test. I have two sandboxes (one is where we are developing; the second is for testing). In the first, ...
0
votes
1answer
26 views

UnitTestException: Maximum stack depth has been reached_Trigger Test class

I have 2 queueable classes and i have chained them in my account update trigger the logic is like below Trigger Logic- onAccountUpdate { Queueableclass1 que1 = new Queueableclass1(newList); System....
0
votes
0answers
21 views

Covering for loops in test class that sends an email

I can't seem to figure out how to cover the portion of the class within the for loops. I'm not sure if there are additional things to add since it's sending an email. public with sharing class ...
0
votes
2answers
69 views

How to increase code coverage for batch apex test class?

I have created test class for batch apex but it only covers 36% of code. How do I increase the coverage? Below is the test class that I have created. @isTest public class CloseOpportunityBatchTest { ...
0
votes
0answers
24 views

Need help with test class that mimics user input on visualforce page

We have a signature capture box on a visualforce page that was created long before I was around. I'm just changing it from being saved on the old Attachments object. For the life of me, I can't find ...
-3
votes
1answer
51 views

Test class trigger.NewMap trigger.oldMap on opportunity [duplicate]

I need to write a test class on my OpportunityTriggerHandler and I'm having some difficulties to define how to construct the logic & scenarios in my test to test and the data to build in my test ...
3
votes
2answers
128 views

Easy way to loop over Apex class member variables

So I am writing an API client for some third-party service. I get a response as JSON. now I am getting 100 fields as JSON responses but am consuming only 3 of those columns. I am using strict parsing ...
-2
votes
1answer
26 views

Why isValid is true but failed to deploy with error 'Dependent class is invalid and needs recompilation'?

Why isValid = true but even though still failed to deploy with error 'Dependent class is invalid and needs recompilation'? When I run query Select Id, Name from ApexClass where isValid = false it ...
0
votes
0answers
17 views

I have this custom controller for a vf page please help me to write the test class..actually I have written but not covering else and catch [duplicate]

@isTest public class LoanPaymentPdfControllerTest { @TestSetup static void testSet(){ // create Account Account accnt = PFSTestHelper.getAccount(); insert accnt; ...
0
votes
1answer
30 views

Help with Test Class for Apex Trigger to Update Field

I wrote a trigger to strip HTML out of a field (the long text field gets copied from a rich text field and comes in with the HTML). I know it works, I just want to write the test class to verify. Here ...
1
vote
1answer
36 views

How to replicate a UNABLE_TO_LOCK_ROW error in a unit test

We've been seeing the UNABLE_TO_LOCK_ROW issue in our prod org. I've created a retry for DML actions facing this issue to sleep for a certain number of milliseconds between each try and try for a ...
0
votes
1answer
29 views

Pointers on writing test class for ApexPages.StandardController Controller

I have the following Apex Class that I need to write a test class for. I've never done this before and rather new at this. Can someone offer pointers for this test class? public class ...
0
votes
0answers
33 views

Unit Test - Query to fetch Event.who.name

I have an issue for my unit test where i seem to not being able to query the who.name from the Event record. For some reason, even after inserting the Event and querying it, it still gives me that the ...
0
votes
2answers
37 views

Trigger Unit Test, what am I doing wrong?

This works as a class. It has the minimal data I need to insert a record and run my calculation class (not shown). I do see the results in my Earning__c table public static void testInsert() { ...
0
votes
0answers
44 views

List has no rows of assignment to Sobject

I am facing an issue with the below code my List has 200 records but still i am facing this error List has no rows of assignment to Sobject. Could someone please help with the below error on why i am ...
0
votes
1answer
37 views

Test Trigger Auto Convert Lead To Contact

I have the following Trigger but how do I write a Test for this so I can put it into production? trigger web2LeadConvert on Lead (after insert) { Database.LeadConvert[] converts = new Database....
2
votes
1answer
39 views

IntellJ : Test being ignored cause it does exists in server

The issue is related to The intellj plugin : Illuminated Cloud (for SFA), the issue is when i make some local changes and want to run some test i keep getting Test method mehod_name was never reported ...
1
vote
1answer
67 views

Constructor chaining giving method not defined

I have the following class with constructor chaining , but the validations are returning Method not found or incorrect signature class @IsTest global class CalloutMock implements HttpCalloutMock { ...
0
votes
0answers
28 views

Test Class on a trigger which restricts the user to enter more than 100%

I have a custom object: Team Member. It is looking up to another custom object Vendor_Contract (Vendor Contract to Team Member is 1 to many relationship). My trigger accurately restricts users to ...
0
votes
1answer
70 views

Apex Class Test long time running

The following Apex Class Test is running properly in different SBXs inside 5 minutes, however I have another SBX that it´s also a Partial Copy that is running successfully inside 3 hours. Is always ...
0
votes
1answer
31 views

Help with TEST Class using @HttpGet [duplicate]

I have this simple little @HttpGet method. @HttpGet global static List<Case> getCases() { RestRequest req = RestContext.request; RestResponse res = RestContext.response; ...
0
votes
3answers
58 views

Could I call the same method many times in the same test?

Is a bad practice call the same method many times in the same test method? Example: @isTest static void testSelectDevice{ List <Product2> device1 = new List<Product2>(); List <...
4
votes
2answers
76 views

Is it possible to have an APEX Testmethod to see SOME, but not ALL data?

Usually I only need @isTest(SeeAllData=false) But now I need to see some Custom Settings (they count as "data", too). And at the same time I must ensure to see only the Custom Settings, but ...

1
2 3 4 5
88