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

Method does not exist or incorrect signature: void accountdetails() from the type Account [on hold]

@isTest public class RetrivalandinsertTest { @isTest static void testRetrival() { Account account=new Account(Type='Direct'); account.accountdetails(); } @isTest ...
0
votes
0answers
7 views

Keep Opportunity Team default value via UI versus API

Working on the Opportunity Team Member trigger for the first time and I noticed the following weird behaviors: When Opportunity is created, Team Member is auto-added but trigger on team member does ...
0
votes
0answers
28 views

Test cases for LWCs with conditional rendering

I have a LWC component which looks like below <template> <!-- modal start --> <template if:true={booleanField}> <lightning-record-edit-form object-api-name="...
0
votes
1answer
27 views

How do I test for a trigger that inserts a calculated value after insert/update of record?

I'm trying to test for a trigger that insert a calculated duration of Event after insert/update of A Event record. For example, the trigger fills an integer representing hours, calculated from ...
1
vote
1answer
22 views

Uncommitted work pending in unit test with queueable chain and httpcallout

I have a Schedule job that invokes a class and from there i call the Queueable class like this: ID jobID = System.enqueueJob(new NSQueuebleJob(acList)); The queueable class is: public class ...
-1
votes
0answers
27 views

Test class not covering sendemail part in batch class [duplicate]

global class BatchtoSendEmailstoSupportTeam implements Database.Batchable<sobject>{ public String query = 'SELECT Id, UsersId, users.name, users.lastlogindate, users.isactive, users.profile.name,...
0
votes
2answers
25 views

Test Method Fail on Apex class with Meta Object

I am writing a simple api callout for Tsheets, and its working just fine, now when writing the test class, its failing on the line "object results = Meta.get('results')". The error is: System....
0
votes
1answer
27 views

Testing a VF parameter is getting as Null?

I have a VF page that is used for rendering a PDF. All the fields are apex:outputText and getting the values from a form-submission-VF page. I am using just a constructor to set the values for this ...
0
votes
2answers
55 views

Will an apex class run if test methods are specified inside that

I'm having an apex class in which I've written both the controller logic and test class methods. So that I don't need to write a separate test class for that apex class. In case, my test class fails ...
0
votes
1answer
30 views

My test class code coverage is 100 percent but it is giving following error in run

For report event my test class code coverage is 100% but it is giving following error System.UnexpectedException: common.exception.SfdcSqlException: We encountered an unexpected error. Contact ...
0
votes
1answer
18 views

Unit Testing: Passing a value within a method

I have a method like this (this is partial but the rest of it is less important to the question). public static List<Contact> syncList() { List<Contact> syncList = new List<...
1
vote
1answer
29 views

Mock test for callouts in a queuable function

I am having issue creating mock for callouts in a queue. I have done following.  I have a handler (OpportunityTriggerHandler) which creates a job called EnableOnboardingCompleteJob. This job calls a ...
0
votes
0answers
27 views

Test class coverage for class used to schedule apex job

I have the class below that is just a simple page that allows an admin to change custom settings, and schedule an hourly apex job by clicking a button. The test class I wrote doesn't cover the part of ...
0
votes
1answer
45 views

Before Trigger on Lead Conversion doesn't appear to be firing in Test Method

I am writing a test to test lead conversion. The test is failing because the lead has a failing lead validation rule that checks a custom field value that is set using a Before trigger. However, even ...
-2
votes
0answers
24 views

How to Achieve Code Coverage for this class [duplicate]

I am posting my test class as well as the class the coverage is 0% please guide me on how to get a minimum % of coverage on this. public class Ltng_WRole{ public @AuraEnabled String RoleId{get; ...
0
votes
2answers
25 views

How to create multiple test custom setting hierarchy

I am not sure how to create multiple profiles for one hierarchy custom setting. I assume it would look something like this: ConcurrentSessionsPolicyLimit__c defaultLimit = new ...
0
votes
1answer
32 views

Unit Testing: Attempt to de-reference a null object

I have these two unit tests. The first one passes and the second one returns the null reference error. However, when I look at the stack trace it tells me the following method is causing the null ...
0
votes
0answers
11 views

AuthProvider is visible from Test Method

@isTest public with sharing class AuthProviderCtrlTest { @isTest public static void getAuthProviderTest() { List<AuthProvider> providers = AuthProviderCtrl.getProviders() ...
0
votes
0answers
23 views

Need Help for Apex Test Class [duplicate]

i have a problem with test code coverage of my trigger: that's the code: public class OpportunityLineItemTriggerHandler{ public static Boolean isTriggerFire = true; public static void sync(Set<Id&...
0
votes
0answers
16 views

Trigger.newMap and Trigger.oldMap not able to pass the correct values in the test Class! [duplicate]

I have a scenario to cover in the Test Class Whenever Case is assign to queue from User : particular field must get blank: public static void wmgRemoveOldGroupQueue(Map<Id,Case> newMap, Map&...
-2
votes
1answer
18 views

Error: No more than one executeBatch can be called from within a test method [duplicate]

Test Class: @isTest private class UsersFreeze_batch_Test{ static final String COMP = 'HID Global'; static final list<Countries__c> COUNTRIES = new list<Countries__c>([...
-3
votes
1answer
42 views

Regarding code coverage [duplicate]

Below is my class but i am not able to cover single line also , can anyone help me out in this test class, i am not understanding why i am not able to cover single line. global class ...
0
votes
0answers
14 views

can someone help me in writing test class for this standardcontroller extension class [duplicate]

public with sharing class testAddNewRows { public List<ContactWrapper> cwrap {get;set;} public Orders__c con {get;set;} public Integer rowIndex {get;set;} public Orders__c rr; Public String ...
0
votes
1answer
32 views

Set LastModifiedDate in Test class

I am preparing the testSetup() and I need to set the LastModifiedDate of the record one month earlier. Is that possible somehow? Field is not writeable: Contact.LastModifiedDate
0
votes
1answer
20 views

I am writing a test class on Case object with entitlement, and I'm receiving an error message

When I execute my test class of " trigger class" on case object this error message is received: first error: FIELD_INTEGRITY_EXCEPTION, You can’t set an entitlement process' start time after any ...
-2
votes
0answers
27 views

Please help me create a normal test class for my callout [duplicate]

enter image description here> Say what I'm doing wrong my method is not covered by tests @AuraEnabled public static void requestAndResponseCurrency(){ Exchange_rate__c newExchangeMDT = [...
-1
votes
1answer
16 views

test class coverage differences in sanboxes [duplicate]

I have created a test class for a trigger and apex class for trigger code coverage is 80% and test class is 81% in Sandbox1. when I have created same test class for a trigger and apex class, ...
-1
votes
1answer
43 views

I'm a novice developer, please help with writing a test class for this code.Thanks [duplicate]

global class converterSchedule implements Schedulable { global void execute(SchedulableContext ctx) { List<Exchange_rate__c> exchange = [SELECT Date__c, GBP__c, USD__c, EUR__c, ...
0
votes
0answers
36 views

Need help for test class for JWT Auth

I need to cover below class . It is 91% covered but giving NoDataFound public class JWTOAuth{ public static string getAccessToken( Salesforce_Org__c o){ Auth.JWT jwt = new Auth.JWT(); ...
0
votes
0answers
27 views

How to validate Old and New Values of ContactHistory in Test Class

I have an apex class which looks for the old and new values of contacthistory. I am writing a test class for this, but could not write data to Oldvalue and Newvalue. I also tried updating the field ...
0
votes
0answers
14 views

Test Class Failing for a Batch Apex Class [duplicate]

I have created a test class which tests the code for a batch apex class but the code coverage is only 62%. I'm really stuck and don't know how to get over it. I'm new to salesforce and any help would ...
-1
votes
1answer
27 views

Apex Testing Failing at 23%

My test is failing at 23%, an entire section is failing for some reason and I am not sure why, can someone help? The portion that fails is everything from public PageReference send() and below. Here ...
0
votes
2answers
45 views

test class for batch apex not covering execute method

I have written a batch class for cloning the opportunity and updating the stage field. Class is working fine. But test class is not covering the execute method. Logically I felt the test class is ...
2
votes
1answer
22 views

CronTrigger records already exist when running Apex test

I get the error message: Assertion Failed: Job already exist: Expected: 0, Actual: 3 When I run this test: @isTest public static void scheduleJob(){ // arrange // assert System....
0
votes
0answers
14 views

Test Class Code coverage Improvement

My test class @testSetup static void createTestRecords() { User thisUser = [ select Id from User where Id = :UserInfo.getUserId() ]; System.runAs( thisUser) { //creating User ...
-3
votes
0answers
15 views

Please help as i am not able to get the Proper Assert Statement Result in Test Class [duplicate]

Please help me out as my one of the Test Class is Failing because of the Assert Statement in the Salesforce. Please find the logic and Test Class as below: Logic Method : public static void ...
0
votes
1answer
21 views

REST Endpoint Returns NULL in Test Class

I have a RestResource mapped to /Demo/ that I place on a Salesforce Site. The rest resource works great, including the parameters. However, in my test class I cannot get it to return anything to ...
-3
votes
1answer
56 views

Not able to get the expected Assert statement in my test Class

My Assert Statement is failing in the below logic and i am not able to get the proper expected value , Please find the Codes in the Screenshots. Logic: public static void wmgRemoveOldGroupQueue(...
-1
votes
0answers
23 views

Test class giving following error System.NullPointerException: Attempt to de-reference a null object [duplicate]

we write a apex class -` public class InvokeReportExportPolicy implements TxnSecurity.EventCondition { public boolean evaluate(SObject event) { switch on event { when ReportEvent ...
0
votes
1answer
33 views

How to unit test the method that schedules an apex schedulable class

I have a method that executes the following code , I am not able to find any thing from CronTrigger to verify the scheduled job public static void ScheduleStatusChk(Id batchId, Set<Id> ...
0
votes
1answer
36 views

Alternatives to RunAs for user context in test classes?

I need to run a test method in the context of a user because of a conditional default field being set based on parts of the users email address. The problem: I only need the users email address in ...
3
votes
1answer
29 views

Unit Tests on Bounced Email

I need to write a unit test on some business logic that happens after the Contact IsEmailBounced field = true. The field is not writeable though. My question is how can I create a test contact with ...
1
vote
0answers
52 views

Test Class for TxnSecurity.EventCondition Implementing Class || Transaction Security 2.0

With Event Monitoring 2.0, I have successfully been able to create a class for Report Export Event. Can anyone assist with the Test Class, as all the field behind ReportEvent Big Object are non-...
0
votes
1answer
28 views

Write a test class for a lightning component which overrides a standard action

I have written a Lightning Component that adds a google address lookup to a custom object. I have replaced the standard new action with a new form. How do I write a test class? I can't automate the ...
-3
votes
0answers
21 views

test void class for production migration [duplicate]

I have this class that makes a callout to get dollar exchange. I call this from an Apex schedule job every day. Im trying to migrate this to production but i need to add the test class but i dont know ...
1
vote
1answer
38 views

on updating case in test class, trigger.new has the same value as trigger.oldmap even after update

I have written a test class to cover logic written on before update trigger. The test class is failing at the assert step and upon checking i found that OwnerId in both trigger.new and trigger.oldmap ...
2
votes
0answers
39 views

Apex Batch Test - works if I populate only one account, fails in setup with 2 accounts

I have written my first Apex batch processing class. It works when I manually create records and run it in my sandbox. It is very simple. We've added a set of fields that can have up to 3 values: '...
0
votes
0answers
13 views

How to write help class for the below trigger [duplicate]

trigger ActiveCountContactOnAccount on Contact (after INSERT, after UPDATE, after DELETE , after UNDELETE) { Set <Id> accountIds = new Set <Id>(); List <Account> lstAccountsToUpdate =...
4
votes
3answers
118 views

How to mock ApexTestQueueItem, AsyncApexJob, and ApexTestResult for test coverage?

I'm currently working on a set of classes that do the following: A class that when instantiated and executed, queues all Test classes in Apex to run by inserting ApexTestQueueItems. I call this one ...
6
votes
1answer
56 views

How can I unit test a http callout that uses a certificate?

The .setClientCertificateName method of the HttpRequest class requires a string that is the name of a certificate in the organization. In a unit test class, is it possible to mock this method? When I ...