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
2answers
271 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
46 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
125 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
29 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
50 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 ...
0
votes
2answers
36 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
36 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
21 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
24 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
17 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
22 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
61 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
105 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
85 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 ...
-1
votes
1answer
17 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
48 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
118 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
55 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
30 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
103 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
31 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
17 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 ...
0
votes
1answer
55 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
82 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(...
0
votes
1answer
37 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
71 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
38 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 ...
2
votes
0answers
134 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
41 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 ...
1
vote
1answer
51 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
45 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
14 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
283 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 ...
7
votes
1answer
148 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 ...
0
votes
0answers
17 views

how to add Loop conditions in apex test classes? [duplicate]

Could anyone help me how to write a test class for this logic.I'm little confusing here. public with sharing class XMLparserForIds { public String XMLString1 = '<?xml version="1.0" encoding="...
0
votes
2answers
47 views

test class for future callout Json.deserialise

My Class global class CreditActionSessionObjMgmt { @future(callout=true) static webservice void deleteSessionRecord(String sessionRecIds) { if(sessionRecIds != null ) { ...
0
votes
2answers
46 views

Overall Code Coverage including unrelated classes as well

I have a sandbox org where I've created a trigger that calls another class containing a future method for final HTTP request. I have also created a test class and MockHttpRequest for it which is able ...
0
votes
0answers
1k views

Advanced Apex Specialist - challenge 8 - Challenge Not yet complete… here's what's wrong

I have this error when I am trying to complete Salesforce Advanced Apex Specialist. Ensure that you have at least 12 products created and that OrderExtension is still working as specified in the ...
0
votes
2answers
75 views

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY

Below error I got while running test class.My test class results fail.Anyone have some idea please share with me. Error Details : System.DmlException: Insert failed. First exception on row 0; ...
0
votes
1answer
60 views

Rest Callout Apex Test: How to Test @AuraEnabled Method?

guys! I have a problem with one method in my Apex class, which I need to cover by tests. This class uses "GET" callout and checks, if the input field is empty (null). If it is, the @AuraEnabled ...
0
votes
1answer
83 views

Rest Callout Test Class : How to Cover @AuraEnabled method?

I'm new to Salesforce and now I'm struggling with one task. I need to make test class, but I'm wondering: how do you cover the second @auraEnabled method with If statement? Here is the code: Apex ...
0
votes
1answer
27 views

In Test class no result for Order.Account.RecordTypeId

In a test class, I want to update Account information depending on the record type. The information to update comes from the Order object. I have created a test account with the according record type. ...
-3
votes
2answers
75 views

How to convert String to list<object> for a test class [closed]

I have a Json getting it in Aura Controller, and for test class, I am mimicking the Json into a string . Original JSON = [{"subid":"a4wgwe00000DfDRAA0","totalgs":"25","Revenue":"17"},{"subid":"...
1
vote
0answers
51 views

Test Class failing with Too many SOQL queries: 101

My test class is public static testMethod void loanSetDelegatedApprovers() { list<User> userList = new list<User>(); list<Approval_Delegate__c> adList = new list<...
0
votes
2answers
303 views

userinfo.getuserid() returning null in test class

I have a test class which inserts partner user for testing. So, when I pass userinfor.getuserID(), it is returning null due to which my test class is failing with error "System....
3
votes
1answer
106 views

Apex batch class test not running execute?

I have written a batch class to mark a certain number of an object in a date range to be marked for review, and it is working when called on from a visualforce page, but it does not work when called ...
0
votes
0answers
19 views

How to write test class for the below class. I tried alot but it not covering [duplicate]

public class LeadAssignment { public Set<String> nullParamsSet; public LeadAssignment(){ nullParamsSet = new Set<String>(); for (NullParameters__c np : ...

1
3 4
5
6 7
77