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

Test Class for Business Hours Check

I am trying to build a test class for my new trigger and part of the trigger is to check current time against the org business hours then set it as a boolean yes/no. Code: DateTime now =system.Now();...
-1
votes
1answer
16 views

Test Class Failing-Logic to process Opportunity data

I'm having trouble getting my test class to pass tests. I am Getting: System.DmlException: Update failed. First exception on row 0 with id 00654000008inR8AAI; first error: ...
1
vote
2answers
28 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 ...
0
votes
1answer
34 views

Regarding moving createtestdata method to @testsetup

I created a method Createtestdata which is called in all the methods in testclass, So when i am trying to move this Createtestdata method to @testSetup as the salesforce best practice to move common ...
1
vote
1answer
22 views

How to create a unit test for custom objects meta?

We are building a package that creates custom setting with reference to custom objects. Then we use settings to create records for these custom objects. How we can create unit test in the package for ...
0
votes
0answers
14 views

Apex Code Coverage for if/else if test class [duplicate]

if (userList.size() > 0 ) { String profileName = userList[0].Profile.Name; if (profileName == 'CP_CorporateAdminUser' || profileName == CP_SystemConstants.CORPORATE_OPERATION) { ...
0
votes
0answers
40 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="...
-5
votes
0answers
27 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
8 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
1answer
344 views

write test case for file upload functionality

I have a upload feature that takes a file from user(only pdf allowed) on visualforce page and then insert it in notes and attachment section of a record.My code works perfectly fine. However, I don't ...
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 ...
0
votes
1answer
681 views

How to cover a getter/setter list (populated via query) in a unit test?

TL ; DR : I'm unable to fill a getter/setter list (that is filled via SOQL query) during testing. When unit testing a controller class, a certain {get;set;} list is not getting populated (it is null)...
0
votes
1answer
28 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
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 ...
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
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<...
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
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 ...
2
votes
3answers
1k views

RecursiveCheck prevents trigger from running during tests

I am writing a test class to a handler class called from a trigger. And due to recursive trigger I had to implement CheckRecursive in the trigger and this works fine, until I start testing. Then the ...
0
votes
1answer
255 views

Getting to 100 percent code coverage on my trailhead module “Write Negative Tests Unit”

I seem to be stuck on this trailhead module or write negative tests unit, while I have 93 percent code coverage, I can't seem to get the code coverage to hit 100 percent at the "returnValue" piece ...
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
1answer
693 views

Test Class to cover NotesandAttachment

I am creating one test class to cover this query.The query is covered, I tested one value retrieved but it does not go into for(NoteAndAttachment h:actOpen.NotesAndAttachments) loop. List< ...
-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
979 views

test class for apex class contains external object

how to write test class for the apex class contains external object code snippet!!! Public Class AliasAddressController { Public Address__x addr{get;set;} Public List<Address__x> Adrlst{get;...
1
vote
1answer
105 views

Filter Update Method does not cover with test class

I'm stuck and not sure where I'm going wrong. I have a user handler class that adds the user to a chatter group under different criteria. One when the user is created and one when the user is updated. ...
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() ...
3
votes
4answers
762 views

Lead conversion unit tests throw errors for validation rules that use custom settings

I'm running into an odd issue with some of my unit tests & can't seem to find out what exactly is causing it the problem. Several of my unit tests revolve around converting a lead to an account (...
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
43 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
34 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
21 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 ...
4
votes
3answers
1k views

How to succesfully test AgentWork trigger?

I am using AgentWork trigger in my logic and I cannot achieve code coverage goal. Simple test method: Id cId = [SELECT Id From Case Where Subject = 'Case Subject'].Id; User u = [SELECT Id From User ...
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(); ...
-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, ...
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....
-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
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 ...
5
votes
1answer
161 views

My ApexMocks aren't working - what could be wrong?

Canonical Question and Answer When using ApexMocks, I'm getting unexpected results. What could be the possible reasons? Here are some of the symptoms I observe: Null pointer exception in my service ...
19
votes
1answer
1k views

deserializing JSON to object: different behavior in unit test vs API?

So let's say I've got a class that looks like this: public class APIParams { public String name; public String category; public Boolean taxable = false; } Then I have a ...
-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
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 ...