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

How to create a correct test for knowledge articles?

I'm creating a package with a simple Apex class that retrieves info about knowledge article (Lighting Knowledge). However, I'm having an issue with a test. When installing the package via installation ...
0
votes
2answers
24 views

Moving Apex Trigger From Sandbox To Production And Getting Error During Apex Testing

I am moving an Apex Trigger from Sandbox to Production and this is the error I am getting in the Apex Test: System.DmlException: Insert failed. First exception on row 0; first error: ...
3
votes
0answers
25 views

Simulating a lightning button menu onchange event through jest

I've been trying to write some unit tests for a lightning-button-menu component. With the lwc file as: <lightning-button-menu onselect={onSelectMethod} class="edit-record-wrapper"> <...
4
votes
1answer
118 views

Is there a way to fake a method response using Mock or Stubs?

I have a helper method in my code called canQueryObject, and that method returns a boolean. I have some code that calls the method via the following line of code: if(!myObjectHelper.canQueryObject(...
0
votes
3answers
33 views

How can I remove Read permissions on a Standard Object in a Unit Test?

I need to test a behavior for when users have no access to the Document object; not even Read access. I've started w/ a mock user given the standard "Read Only" profile, and I'd like to use the ...
0
votes
1answer
20 views

Invalid conversion from runtime type List<ANY> to a wrapper class

I have a Map like this: Map<String, Object> seeMap = (Map<String, Object>) instance; system.assert(seeMap.get('fish') != null, true); // this assert passes System.debug(seeMap.get('fish'))...
2
votes
1answer
22 views

Test class data creation - Salesforce Files

I am needing to create test data within my test class to simulate adding a content document link row. I have a trigger on the ContentDocumentLink object, so just need to fire it. The Content Document ...
0
votes
1answer
46 views

Queueable Apex in a Before Trigger

I am attempting to create logic that, on Contact record insert or update, will compare the Phone value of the record to another reference object and conditionally populate a checkbox as a result of ...
0
votes
0answers
12 views

How to activate the FFA Billing Contract status in test class

I have installed FFA Accounting package in my org and now i have write some code on that, so when i tried to write the Test class so in my condition i want billing contract as active, but when i set ...
2
votes
1answer
39 views

Apex code coverage and static boolean recursion flags

I've written two Apex Triggers, one on the Opportunity object, and one on a custom object. These two triggers keep the two objects' checkboxes in sync; setting a value on one object's value sets the ...
0
votes
0answers
4 views

Cases created for portal users before their user is created are not shared with the portal user in unit tests

I'm making some changes to a security model to rely on standard Salesforce security. When I remove a Share Set that grants edit access to an Portal User's Cases because that's redundant, and we need ...
0
votes
2answers
33 views

How to test this return value in catch exception

I'm new to test classes, can anyone give me a help on this? Here's the class: global class CallTimerController { @AuraEnabled global static Integer getMaxCallDuration(){ Id pId = ...
0
votes
1answer
26 views

Test class for a scheduled batch is not firing the batch

I have tried the class in a sandbox and works fine (i.e. it updates all of the accounts based on the attached event records). The test class refuses to fire the batch class and I get 0% coverage. ...
1
vote
1answer
41 views

Scratch org created from Bitbucket pipeline has no Standard User profile

To build DX unlocked packages I am using Bitbucket pipelines. I use the Salesforce configuration template for this. image: atlassian/default-image:2 pipelines: default: #These commands run for all ...
0
votes
0answers
16 views

Help writing a test class for apex class I want to deploy to prod [duplicate]

Public Class controller_SoqlQuery { public List<AggregateResult> medOppsCount{get;set;} public List<AggregateResult> nonMedOppsCount{get;set;} public List<AggregateResult&...
0
votes
1answer
37 views

testing upsert campaign members gives error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []

Testing my apex controller in my dev org runs fine. However, testing the same file in another dev org gives error INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: [] Here is the controller ...
0
votes
1answer
16 views

pass list<string> value in test class

In my class one list of string is there which is get;set; type. i want to pass the value in test class how to do this public class MYController(){ Public list<string> selectedDelList{get;...
1
vote
0answers
24 views

Has anyone been able to set the User.IsCustomerPortal field from a unit test class?

I know the field is not editable but I mean by associating a User record with a Contact/Person Account record in your test data, somehow it gets enabled? Do you know? The reason I need this ability ...
1
vote
2answers
59 views

Is it a good practice to use a static variable in a Test Class and use that in the actual class instead of Test.isRunningTest()?

I've read about using a static variable from a class in the test class but I'm wondering if this is legal enough to do. @isTest public class myTestClass{ public static Boolean mySwitch = false; ...
0
votes
0answers
17 views

Please assist me in writing test code for this working piece of code. I am new to testing [duplicate]

I'm stuck at 38%, Its just cover the last part of code(callout portion), I have tried several ways but it just cover till line ' parse_id.nextValue(); ' and after that line it mark as red all the ...
0
votes
0answers
15 views

Unit test for a update list Apex Class [duplicate]

i need to write the Unit test for my class in apex, but i don't understand how to function a Unit test, i read many articles for unit test but i don't understand how to work, my class is this, please ...
0
votes
2answers
38 views

Fatal Error while deploying apex classes to production [closed]

I have created 3 new apex classes and test classes for the same.In sandbox, test class code coverage is more than 90% for all the classes. While trying to deploy to production, I am getting error as ...
0
votes
1answer
23 views

unit testing - if record is created with certain record type

I have a function createWithRecordTypeIfExists(String recordType). Its logic goes like this: Check whether a record type for this object exists in the org. If yes, create a new record with this ...
-2
votes
1answer
44 views

I am getting stuck here, I just need test apex /snippet /mock for this. Any input will be highly appreciated [closed]

I am just new to apex testing, I am getting responce from Trigger upon that i am moving further in my class. let me know id there is a way around to get better understanding to develop test cases. ...
0
votes
2answers
20 views

Create exceptions in test classes for a process builder?

Is is possible to create exceptions in a Test Class for (example) Process Builder "XYZ NAME"? To avoid the test class running that process. Right now my work-around is to manipulate the criteria in ...
0
votes
2answers
29 views

Cannot write test Quote object for Trigger

I have a Quote trigger for which I am trying to write tests. Here is my test class. However, I am getting some wierd errors while writing this. @isTest public class TriggerQuoteTest { @...
0
votes
0answers
25 views

How to increase the code coverage for the following Test Class, currently it covering only 50% [duplicate]

Actual Class: global class ITSSFAutoRejectBatch implements Database.Batchable<SObject>, Database.Stateful, Schedulable { global String[] toAddresses = null; global integer batchSize = 100; ...
0
votes
2answers
43 views

Testing or writing a test class for random string generator class

How can we unit test a random string generator class of this given code. I do get 100% code coverage, but I feel like the test is not executed properly. Any solutions to this will be helpful. Random ...
0
votes
3answers
57 views

System.AsyncException: Maximum stack depth has been reached. while writing in test class

I've got a requirement to perform queueable apex in a trigger my class working fine, but while writing a test class for queueable apex I'm getting an exception. Could anybody can help me. Trigger ...
0
votes
1answer
25 views

DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record [closed]

Account parentAccount = TestUtils.createAccountWithRecordType(Schema.SObjectType.Account.getRecordTypeInfosByName().get('Parent Account').getRecordTypeId(),false); parentAccount.City__c = '...
0
votes
0answers
62 views

Test class error: System.NullPointerException: Argument cannot be null

Please help me on fixing this error in my test class @isTest private class ItemizedReceiptTest { static testMethod void testMethodPostive(){ Product2 prod = new Product2( Name ...
0
votes
1answer
28 views

How do you write a test for a class that clones? [duplicate]

I have the following code that clones an asset and its' children... public class Cloner { public Asset root_asset { get; set; } public Asset cloned_root_asset {get; set; } public ...
0
votes
1answer
89 views

Test method is failing error in test class

I am fetching the data of Account from the various Instances My Apex controller: public class Accounting{ public list<Account> lic{get;set;} public list<Account> licUpdated{...
4
votes
2answers
153 views

Send out email when Apex Queueable fails and test it

This question definitely is a duplicate of many questions here, but after reading most of them I am still somewhat clueless. Question 1: why I can't just catch exceptions in the execute and send an ...
1
vote
1answer
41 views

System.QueryException: Implementation restriction: ContentDocumentLink requires a filter by a single… in test class?

I'm facing System.QueryException: Implementation restriction: ContentDocumentLink requires a filter by a single Id on ContentDocumentId or LinkedEntityId using the equals operator or multiple Id's ...
0
votes
0answers
16 views

Test Class - SOQL in Test Returns No Results using Database.Insert(RecordList,DML), but works using Database.Insert(RecordList)?

I am creating test coverage for a new Lead Process we've built for our company. To properly test this deployment, I need a list of Leads to show as being Inserted by our Pardot API connector user, and ...
2
votes
1answer
25 views

How to throw or cause an Access Level exception in a test class

anyone know how to throw an access level exception in a test class to cover the below code sample? I'm assuming the object being inserted with Database.insert needs to have sharing settings modified ...
2
votes
1answer
105 views

LWC - Unit Testing NavigationMixin.GenerateUrl

I've been looking to start unit testing the Lightning Web Component I've created with LWC Jest and I am running into some issues in creating my component that is making use of the NavigationMixin ...
0
votes
0answers
41 views

System.ListException: List index out of bounds: 0 in test class when we try to query ProcessInstanceWorkitem [duplicate]

I am getting List index out of bounds exception when I try to query ProcessInstanceWorkitem in test class. Below is the code snippet in the main class: ProcessInstanceWorkitem[] piw = [SELECT Id ...
0
votes
0answers
21 views

How to write Apex test for record creation? [duplicate]

I'm having a hard time writing up a test class for the following Apex class: public class logger { @AuraEnabled public static void insertLog(string name, string id, string location, string ...
0
votes
0answers
16 views

I need help with a test class unit [duplicate]

I have the following trigger and I would need some help in creating the test class. trigger listingLocationUpdate on pba__Listing__c (before insert, before update) { //Mantiene actualizado el ...
-1
votes
1answer
20 views

Test Method for Custom Controller that references Lists in Loops

I have the following custom controller that is pulling some Lists and subsequently looping back through the Lists to do some sums on the values to display them on a Visualforce Page I have only got ...
-1
votes
1answer
33 views

Not able to cover the IsConverted Logic from test class

Class: public class classname { public static void MethodName(List<Lead> listNew){ Set<Id> OppIds = new Set<Id>(); for(Lead lead : listNew) { if ...
2
votes
1answer
55 views

ERROR: Cannot create an AuthInfo instance that will overwrite existing auth data

Background I get this error message: ERROR: Cannot create an AuthInfo instance that will overwrite existing auth data. In the VSCode output panel, when I try and run a unit test: Starting Run ...
-1
votes
1answer
24 views

Test class For Standard Apex controller

I am Getting Error System.QueryException: List has no rows for assignment to SObject in Test class For newservice object , It will create new service implicitly by trigger Controller Class ...
5
votes
3answers
199 views

How to cover method return statement in Apex Class?

I'm writing a test for a schedulable class and so far it's working fine but I can't get the return statement to be covered by the test class. I'm missing something here and can't see it. The final ...
-4
votes
1answer
35 views

Can anyone provide me the test class [closed]

public class EmbeddedDocuSignRESTController { public Static String Loan_Prodcut = 'Loan'; public Static String Lease_Prodcut = 'Lease'; public Static String StageName_DocsExe = 'Document ...
1
vote
1answer
23 views

Test error condition in finish() method of Batchable class

Trying to figure out how to test error condition in the finish() method of this Batchable class. I am testing the error condition in the execute() method by calling it separately in the test and ...
1
vote
1answer
27 views

Test error condition in batch class with callouts

I have an Apex class with a callout (oregonDistricts.apxc) and I have two tests written that test both the success and error conditions. These tests are passing and the class has 100% code coverage. ...
0
votes
1answer
22 views

How do I get my test class to cover the extension controller?

I am getting only 1% code coverage - please help on how to get it fully covered! My page (minus all the html which references variables from the class): <apex:page id="ApplicationFormPDF" ...