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

Record inserted in the test class is not coming up in the query

I am writing a test class where I am inserting an Order record using the following piece of code Order orderRecord = BaseTestUtils.createOrder(contract, true); insert orderRecord; ...
1
vote
0answers
26 views

expected vs actual in system.assertEquals is reverse

When my test fails, the error message seems to reverse the meaning of Expected and Actual, and so I want to clarify if this is normal. I am running my tests in the developer console. Assert statement: ...
0
votes
1answer
14 views

test class to prevent deletion

I am writing a trigger to prevent detetion of certain accounts trigger doNotDelete on Account (before delete) { // Prevent the deletion of accounts if it is a customer for (Account a : Trigger....
0
votes
1answer
27 views

No code coverage on attachment test class

I could use some help with the code coverage on my class. The test class is not complete. I was trying to just get coverage on the program object and then work from there but I am not getting any ...
1
vote
1answer
21 views

Turn off Automatic Affiliation Management in test class

We have NPSP installed as a managed package in our org and we have Automatic Affiliation Management turned off. I'm trying to test a trigger I've written on the Affiliation object (...
0
votes
1answer
42 views

Unable to fetch relationship data in apex test class for data created in @testSetup

I created an account, a contact and a user then connected all 3 to create a test community user in a method annoted with @testsetup. I ran my test in context of the community user created previously ...
0
votes
0answers
20 views

Overall code coverage showing zero after running test class

Every now and then I encounter the following issue after I run my test classes, they all marked as completed and pass, however the class in the section Overall code coverage shows as 0 (some of them ...
0
votes
1answer
25 views

Apex method not changing record type of an object

So Im making an Apex class that I want to push to production that will change the record type of an object, to a different record type. Here is the class below: public class removeclassy { List<...
0
votes
1answer
24 views

Test Coverage Issue with Site.getSiteId()

I am unable to cover the below function in test class as siteId is always returned null Id siteId = Site.getSiteId(); if (siteId != null) { //Community user logic -- THIS IS THE PART THAT IS NOT ...
2
votes
1answer
22 views

Help Understanding How to write Test Class for Apex HTTP Post

So I've been through quite a few posts/questions already looking for enough information to have this "click" for me, but I'm still missing something. This is my first time working with ...
0
votes
0answers
41 views

Write a Test for extension HELP [duplicate]

Hi Im new working with apexcode and I Crate a Class in sanbox, but when I try to upload to production it says that my coverage code is 73% this is my code public with sharing class ...
0
votes
0answers
22 views

INVALID_ARGUMENT_TYPE on ContentVersion insert in test method, varies by sandbox

I'm getting an exception in one sandbox and not another, anytime I try to insert a ContentVersion. I created a simple test to distill this down to its essence: @isTest public class SampleTest { @...
-1
votes
0answers
27 views

Code coverage for batch clas in handler class

I have a trigger handler, From trigger handler I am calling a Batch class. For trigger handler I have written a test class. Test class not covering the batch class calling line in handler class. ...
1
vote
1answer
23 views

Nested SOQL Not Working in Unit Test

I have the following code in my unit test to insert data: Account account = new Account(); account.Name = 'Account Name'; insert account; Opportunity opportunity = new Opportunity( Name = '...
3
votes
3answers
202 views

How to mock System.isFuture()?

I am writing some tests and I have encounter a problem. In my main app I have the following logic: public static void main() { if (System.isFuture()) { System.debug('Is future'); // ...
0
votes
1answer
35 views

need help to fix apex batch test

this code not cover test for 100% global class closeAllDealsMonthAgo implements Database.Batchable<SObject>, Database.Stateful{ List<Opportunity> listRecords = new List<...
0
votes
0answers
12 views

Creating a Test Class for 2 Classes [duplicate]

In order for Territory Assignment rules to fire on Account creation and Update, I have got 2 Classes working (with Triggers), however I am struggling to create a Test class for these, any help would ...
1
vote
1answer
77 views

No Code Coverage on Apex Class

I have an Apex Class where none of the lines are being covered by my test class. The test class is passing and I'm getting the results I expect. I also checked the box "Always Run Asynchronously&...
0
votes
0answers
33 views

Help with Code Coverage for Milestone Completion Trigger [duplicate]

I have minimal Salesforce development experience and I am struggling with getting a test class built to cover 2 triggers. In the following Salesforce help article there are 2 triggers, 1 to auto-...
0
votes
1answer
34 views

How to cover a catch statement in a test class?

I have a simple after insert trigger which inserts a task when an account is created. I am struggling to cover the catch statement in my test class. Is there a way to cover it? Apex Trigger trigger ...
0
votes
1answer
35 views

Add cart in the commerce cloud test class : ConnectApi methods are not supported in data siloed tests

If we use ConnectApi.CommerceCart.addItemToCart , exception occured : System.UnsupportedOperationException: ConnectApi methods are not supported in data siloed tests. Which method or class to use to ...
0
votes
0answers
19 views

Case Milestones not created when testing apex class

Recently I stumbled upon problem getting code coverage for Apex code that evaluates case milestones by their target date values. When trying to create case in test class it does not create case ...
-1
votes
2answers
29 views

What is test class for below code? [duplicate]

public class UtilityClass { public static String getDescribedObjects( List lstSObjectType ) { // Globally desribe all the objects Map<String, SObjectType> globalDescribe = Schema....
1
vote
1answer
41 views

ConnectApi.ConnectApiException: This isn't a buyer account

When i am writing test class for Commerce Cloud. Then Account is necessary is buyer account. How i can enable Acount.IsBuyer field to true in test class. In UI i can enable as buyer account by click ...
0
votes
1answer
33 views

CronTrigger.TimesTriggered is not incrementing after Test.stopTest() in Apex test class

I have a scenario in which an email is being sent to Users having admin profile at the end of the month for Closed Opportunities. Code seems to be working fine when tested in execute anonymous window ...
0
votes
0answers
55 views

Deployment to Production org through VS code [duplicate]

I am trying to deploy the components to production org through VS code. I am getting the below error "sf:INVALID_OPERATION: INVALID_OPERATION: testLevel of NoTestRun cannot be used in production ...
0
votes
2answers
29 views

Apex tests and Run test option

I have a question about running apex tests and why i can't see that "Run Test" under IsTest annotation just like on the first screenshot What i see is something like this
-1
votes
0answers
25 views

Getting Method does not exist or incorrect signature error

I'm getting the following error when I try to save my Test Class: line 33, column 12: Method does not exist or incorrect signature: void prepareCMUrl() from the type NWTAttachCMController Here is my ...
0
votes
1answer
32 views

Encountering Constructor not defined in test class

I'm scheduling a batchable class that deletes records from a custom object. The test class for my scheduled class saves without errors. However, I'm getting a "Constructor not defined: [...
-1
votes
2answers
27 views

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id:[] error on deployment of test class to UAT

I am trying to deploy the test class to UAT, the test class is working fine dev and have 100% coverage. But when the same test class in deployed to UAT I am getting ...
0
votes
1answer
27 views

Test data not visible by Dynamic SOQL

I have an seemingly simple aura enabled class for agreement lookup which returns maximum 8 records using dynamic SOQL. This class works fine from UI perspective. No issues so far while testing. My ...
0
votes
1answer
70 views

LWC Error: Cannot set property 'textContent' of null

I have an lwc class with the following HTML: <template if:true={showModalButton}> <lightning-button class="right-col-button" variant="base" label={modalButtonLabel} ...
0
votes
1answer
18 views

System.TypeException: Invalid conversion from runtime type List<ANY> to Map<String,ANY>

I'm writing test class for one of my method and getting this error: Method: public String onLoadLog(String loaddata) { Map<String, Object> LogData = (Map<String, Object>) JSON....
0
votes
2answers
45 views

test class passing but not covering execute method

I have coded a batch class and am now working on the corresponding unit test. I believe I've inserted all the objects I need but none of the actual execute method is being covered, despite the test ...
-1
votes
2answers
19 views

Difference in Unit test?

Is there any difference between these 3 section of codes? In first and second one I am getting an error that Price_c variable doesnt exist but in third one I do not. List<Levis__c> leviList = [...
0
votes
2answers
29 views

Process Builders conflicting with Unit tests

I am sure this has been asked before but what we are seeing is unit tests failing due to a process builder change or a new PB being added . We either see flow execution error we run out of CPU time ...
1
vote
0answers
33 views

Test Class not working (Case/Event)

I need Test Class to test the standard functionality : When you change a record’s owner, some items that are related to the record are also transferred to the new owner. In my case Case owner changed ...
0
votes
1answer
11 views

Test class for approval process with formula fields

I am trying to write a test class for an email controller but keep getting tripped up on the Approval Process part. The long & short of it is that my approval processes for SBQQ__Quote__c in my ...
1
vote
0answers
24 views

Even with KnowledgeUser I get: Be sure the action is valid for the current state of the article, and that you have permission to perform it, exception

I have the below test class: @isTest public static void batchManagementDraftTest() { User u = TestDataFactory.createUserWithRoleLeader(); User u2 = TestDataFactory....
0
votes
1answer
25 views

Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY , AVA_SFCORE.OppTriggers: execution of BeforeInsert

I have a problem in my ORG, Whe I excute my Test Class I receive this error bellow : System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ...
1
vote
0answers
43 views

Intermittent test failure due to Maximum Stack Depth Reached

I have some tests which usually pass, but every once in a while, all of the tests fail with the following message. Is there a revision I can make to my tests to avoid this intermittent failure? ...
0
votes
1answer
41 views

Batch class start method returning null, even after a record has been inserted in the test class

I have a batch test class: @isTest public with sharing class TestBatchManagement { @isTest public static void batchManagementTest() { User u = TestDataFactory.createUserWithRoleLeader()...
0
votes
0answers
18 views

Expect() assertion for modal pop up in lwc test

I have an lwc component which is used for file uploading purposes. Below is the code related to modal pop up from html mark up of the component <template if:true={isModalOpen}> <c-...
0
votes
0answers
24 views

Inserting Content Version via Community User in test class Failing

I think this is very straight forward I just can't figure out the issue behind it. Error: : Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, You do ...
0
votes
1answer
51 views

test class on lead where through an error if email entered is already exists contacts

Apex Class: public class Handler_checkiftheemail { public static void TriggerHAndler(List<Lead> newLeadList){ List<string> LE=new List<string>(); for(Lead La:...
0
votes
2answers
26 views

Using MultiStaticResourceCalloutMock [duplicate]

I am working on a class that makes a callout to a third party API. The third party API needs to be authenticated with a OpenID Connect Auth token. So, in my class, I am making a callout to the OpenID ...
0
votes
0answers
25 views

how to write test class? [duplicate]

how to write test class for this class Multiple objects are included to this method. i don't know how to its cover public static void createAutoIndex(List<EmailMessage> emList, Map<Id, Case&...
0
votes
1answer
33 views

Trigger Test Class with mock callout

I have a before update trigger which makes a future callout. When i am writing the test class for it, i am updating the object in test method to achieve coverage for trigger. However this is causing ...
0
votes
2answers
39 views

Test class for trigger on Opportunity Object [duplicate]

@istest public class Test_TriggerOpportunity { private static testmethod void TestOnOpp(){ List<Opportunity> OppList=new LIst<Opportunity>(); Opportunity Opp=new ...
0
votes
1answer
74 views

How to create a test for the ManagedTopic?

I have an Apex class TopicController that has a method that returns a list of Navigational Managed Topics: public with sharing class TopicController { // Returns a list of all Navigational Managed ...

1
2 3 4 5
84