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
1
vote
2answers
30 views

Apex Unit Test for if == null and return statements

I have a simple helper method in my Apex Code that loads an external ID from a field on the related Case.Contact. I have problems to write a proper unit test that covers the last three lines, ...
0
votes
1answer
28 views

Why should we use system.assert in test class even after enough code coverage?

How to use system.assert in the below test class? @isTest public class a_Call_Objective_Trigger_Handler_Test{ testMethod static void CallObjectiveTest(){ RecordType Callrt = [SELECT ID,...
-1
votes
1answer
39 views

Issues with Apex Test Class

Can you help us with a test class? We are using the class in a LWC and we confirmed that it works when we test it manually. The coverage test stops at around at line 9 after the json serialize lines. ...
0
votes
1answer
24 views

Test class passing but not getting any code coverage

so I am newer(ish) to Apex still and clearly know that I am not getting any code coverage to my Apex class because I am not referencing the method, my question is how exactly would I go about calling/...
2
votes
1answer
30 views

Running the packaged tests while installing with sfdx:force:package:install

Is there a way to run packaged or org tests when we install a Managed/Unlocked SFDX package to an org using sfdx force:package:install?
0
votes
1answer
31 views

What is wrong with this test class? It is not covering, any suggestions? Thanks, [duplicate]

@isTest public class PropRentTotalSumTEST { @isTest static void testFeeCalculation() { Property__c prop = new Property__c(); prop.Name = 'Test'; prop.Monthly_Rate__c = ...
0
votes
0answers
19 views

How to test method that uses Site.validatePassword(…)

I'm writing tests for a custom Apex class regarding the self-registration of a customer community user. One of the methods contains the API call to Site.validatePassword(user, password, ...
0
votes
1answer
21 views

How to test a scheduler class scheduling itself and calling a batch. Check out the code

I have a batch class which is called by an scheduler class which is scheduling itself. I have written a test class which has two methods: One tests the batch and the other the scheduler.Overall the ...
0
votes
0answers
12 views

Does link expiration change when sending previews/test? [closed]

Thought id ask - I have a bunch of view as webpage links ive given that were taken from test emails using the preview and test - just wanted to make sure these links don't expire earlier compared to ...
0
votes
0answers
24 views

Test class for the code below [duplicate]

// Hi Community, I need a help to write a test class for this code, can someone help me with? public with sharing class PropRentTotalSum { public static void RentTotal(List<Fee__c> ...
0
votes
2answers
47 views

Why does controller gives: System.NullPointerException: Attempt to de-reference a null object

I have an apexclass with a pagereference for which I am writing a unittest but this returns an NullPointerException on controller.toCareerPageWithFilters(); what am i missing? public class ...
0
votes
1answer
13 views

Test for Generated Class From WSDL

Should I write unit test for those apex classes generated from wsdl when deploying to production?
0
votes
1answer
21 views

How to test picklist controller apex class

I have a lightning component that works just fine but I need to test a controller: public class PickListController { @AuraEnabled public static List<String> ...
0
votes
0answers
18 views

How to mock multiple post callouts in test - different responses same endpoint [duplicate]

I have some code that is potentially making multiple post requests to the same endpoint within one transaction, then updating records based on the response. I think the code works, but I want to ...
-1
votes
1answer
37 views

How to write test for this trigger [duplicate]

Want to write Test case and unit test for this trigger trigger Autoleadconversion on Lead (after insert, after update) { for (Lead lead : Trigger.new) { if (lead.isConverted ==...
0
votes
1answer
27 views

Test Class for Apex Batch Job generating Invoices covers only 38%

Please help me to finish my Test Class for the following Batch Job generating Invoice creation. Apex Batch Job global class InvoiceGenerateBatchJob implements Database.Batchable<SObject> { ...
1
vote
0answers
13 views

How Test LogoutEventStream

I am creating a functionality to count the number of minutes that a user is connected. For this I use the LogoutEventStream in a trigger. The problem is that I don't know how to test it. I already ...
1
vote
0answers
7 views

Dynamic Test Class for Trigger in managed package

Problem Using a managed package and Metadata API, we are deploying a trigger class that calls to a global packaged class. We are deploying also the Test Class dynamically for the object where we are ...
0
votes
1answer
31 views

Unittest eror: System.NullPointerException: Attempt to de-reference a null object

I am writing a unittest for my apex class but get an error System.NullPointerException: Attempt to de-reference a null object on my unittest for variable: testoptions Apex class public class ...
4
votes
2answers
83 views

Does MIXED_DML_OPERATION behave differently in test methods depending on how you run them: Test Execution vs. Deployments?

We typically validate our source control nightly and run all tests. This is essentially a validate only deployment running all tests against production. All tests pass. However, if we were to run ...
0
votes
1answer
18 views

How to test a List<SelectOtion> in unittest

How to test a List<SelectOtion> in unittest. I have the following apexclass public class WebToObjAttachments { .. public List<SelectOption> CountryOptions { get { ...
0
votes
1answer
20 views

How to avoid in unittest Error: Invalid type: ZuoraObject.ConvertToZuoraInvoiceDatas

I have a following class with method public virtual class ZuoraObject { .. public static List<InvoiceData> ConvertToZuoraInvoiceDatas(List<Zuora.zObject> zInvoiceDatas) { if (...
0
votes
1answer
30 views

Help to get 100% test coverage for apex class requiring to populate only one of the two custom fields

Here is my apex class with validation rule to populate one of the two custom fields, and not allowing to populate both custom fields at the same time: public with sharing class FieldnotEmptycontrl { ...
-1
votes
0answers
25 views

Test class - INVALID_CROSS_REFERENCE_KEY, Record Type ID: this ID value isn't valid for the user [duplicate]

I have a test class that does not use 'run as'. I am getting this error when I try to insert a custom object record - INVALID_CROSS_REFERENCE_KEY, Record Type ID: this ID value isn't valid for the ...
-1
votes
0answers
27 views

Unable to pass Test Class Class Error System.QueryException: List has no rows for assignment to SObject [duplicate]

i am unable to pass a test class because of the above error can anyone pls tell me the solution,here is the code of test class and class @isTest static void validate_AccountCallCleanUpBatch_MRG() ...
1
vote
0answers
22 views

How to get code coverage with logic based on screen flow variables?

I am trying to get code coverage to deploy a class that depends on variables set in a screen flow. I've read various articles saying it's not possible to get coverage for screen flows. Is this ...
-1
votes
0answers
11 views

Need help with Salesforce Test Class [duplicate]

This is my Apex controller public class QuoteController { //Get Opportunity_Quotes__c Records @AuraEnabled public static List<Opportunity_Quotes__c> getQuote(Id id,String ...
0
votes
0answers
36 views

Unit Test - No Code Coverage with Wrapper Class

Having issues getting any code coverage, no lines have been covered yet i am returning the data to the test method that I want and the System Assert is running as anticipated Class to Be Tested ...
1
vote
1answer
39 views

Best tool for seeing highlighted covered Apex Code while writing test class

Currently I do most of my development in VScode using sfdx. For writing test classes, I need to see which lines are covered in Apex classes I write. In DX, running commands (see below) to get ...
6
votes
0answers
29 views

Are ContentVersion unit tests impossible using a Community user?

I have some unit tests that pass when using System.runAs with standard user but fail when using Communities user. The error is (note the mention of NetworkId): ...
0
votes
1answer
32 views

Custom settings in tests if it's trigger

I have a trigger with custom settings and test for it. And I have an example how to test it right: @IsTest void testWithSettings() { Example_Settings__c exampleSettings = Settings.getExample(); ...
3
votes
2answers
151 views

Queueable apex still executes in test context even if Enqueue Job is not called between Test.startTest() and Test.stopTest()

According to Salesforce docs: All asynchronous calls made after the startTest method are collected by the system. When stopTest is executed, all asynchronous processes are run synchronously. ...
1
vote
0answers
24 views

Unit tests for MessagingSessions in Service Cloud

I'm struggling with writing apex unit tests for my new Messaging Channel. I just configured Facebook Messenger as new messaging channel for existing OmniChannel. When someone is starting conversation ...
0
votes
1answer
20 views

How to add pick list value into test class dynamically

I want to add pick list value in test class i.e when i select pick list value it should be updated/added in the corresponding test class
2
votes
1answer
37 views

Test Class for ContentDocumentLink causing Internal Salesforce Error

I have a test class that is inserting a ContentDocumentLink between a ContentNote (SNOTE) and a custom object. Everytime I try the insert it causes an Internal Salesforce Error. I have absolutely ...
-2
votes
0answers
24 views

How do I write a VisualForce Controller Extension Test using System.RunAs

Question: Why does a VisualForce page which accesses a record out of the Users sharing group work, but a unittest using System.RunAs cannot find the record? User is of ProfileA User Owns Opportunity ...
0
votes
1answer
29 views

How to cover the catch block for after insert Trigger?

When you create a Barrel, a Filling is also created. Is there any chance to make a fake error in unit test between Barrel and Filling to crush the upsert process and cover the catch block? Helper: ...
0
votes
1answer
12 views

Test Coverage discrepancies for QuickAction.QuickActionDefaultsHandler

Test Class runs successfully and test coverage is 100% but fails during deployment saying "Your Code Coverage is 70%". @isTest public class DefaultSignatureForEmail_Test { static { ...
2
votes
3answers
32 views

Do we get new governor limits in test classes for each test method?

Do the governor limits refresh for each testMethod or we just get specific governor limits for each test class (for instance - SOQL limits 100+100 for test.start/stop)? Please don't tag best ...
-1
votes
2answers
40 views

Can't cover DMLException with my test

I'm trying to cover my Exceptionm But I don't know. how to do this. When I try to insert a record without Required fields, I get the System.DmlException: Insert failed. First exception on row 0; first ...
1
vote
3answers
45 views

The custom setting parameter in unit tests is NULL

I'm getting null in my code here, while running a unit test, but in Execute Anonimous Window there is a right value in System.debug(). What the hell? Maybe I should run the test as System ...
0
votes
1answer
28 views

Too many callouts error when running a test class

Any input would be greatly apprecaiated. I'm attempting to execute a test class, but when I run the test, I get a message saying 'too many callouts: 101' in the logs and the test fails to complete. ...
0
votes
0answers
22 views

Getting INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY when mocking an Object using Stub API

I am mocking a routing rule object by using the JSON list below that has an ID of type Routing_Rule__c. The Test is about creating some rules and setting some flags that would cause the lead object to ...
0
votes
1answer
40 views

getting an error System.DmlException: Update failed. First exception on row 0 with id 00N000000FqP2cIAF; first error:

I am getting in MyTestClass System.DmlException: Update failed. First exception on row 0 with id 00N000000FqP2cIAF; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access ...
0
votes
1answer
33 views

I am getting on so many error on my test class

I am getting an error Illegal assignment from String to Date and when I run the test class another error System.QueryException: List has no rows for assignment to SObject" Account acc = [...
-2
votes
0answers
24 views

Not covering Map<String,Object> and pushnotification method in test class [duplicate]

Can anyone help me in increasing coverage of below class which is just 31%.I am trying to insert data to cover all if-else conditions and pushnotification method but unable to do so. public without ...
-2
votes
0answers
29 views

Test class not covering [duplicate]

Need help in test class.Not able to cover these lines:- careTeamUserMap.put(userRec.AccountId,userRec); wrap.hcpImage = careTeamUserMap.get(caseRec.APS_HCP__c).SmallPhotoUrl; ...
0
votes
1answer
40 views

Issue with Test Class unable to cover SOQL query and insert statements

I have created a VF page that is basically a form. The issue is that my test class is unable to cover the SOQL statement inside the retrieve method. Also, it is unable to insert ptw or cle in save ...
-2
votes
0answers
8 views

Need test class code for AgentWork Apex trigger [duplicate]

I've created an APEX trigger code which changes the status of a case to In Progress when accepted from the omni channel The code works in the sandbox but I can't deploy it as I get an error "Your ...
0
votes
1answer
16 views

Workflow Task Error When Trying to Deactivate a User from a SandboxPostCopy Apex Test

I'm trying to deactivate a user in an apex test. But am getting an error that the user (that I just created in the test) in being used by workflow tasks. The class implements SandboxPostCopy and is to ...

1
2 3 4 5
77