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

Unit Testing for ContentDocument processes

Here is my testclass: ContentVersion contentversion = TestDataFactory.createContentVersion('test', 'test', 'test'); Set<Id> testSet = new Set<Id>(); testSet.add(...
0
votes
2answers
41 views

How to test Job states for a Apex Test with CronTrigger being read only?

I have the following function in a class that implements System.Schedulable: @TestVisible private void rescheduleJob(CronTrigger me, ISchedulable item, MySchedulableContext myCtx) { if (me....
2
votes
1answer
45 views

Deployment / Validation apex test results

Does anyone know where the test results (especially runtime) are stored for tests that are run during a validation/deployment ? I know the objects where the test results are but how do they relate to ...
2
votes
0answers
71 views

Internal Salesforce Error occured when inserting CartItem via Test Class

Since Monday (May 10, 2021), we've encountered an issue in our test class that we didn't encountered previously. There was a Salesforce update on May 10 so I suspect this was the cause of our issue. ...
2
votes
1answer
61 views

Is there a way to detect that an Apex test is running within the packaging process?

We are hitting some CPU limit challenges undocumented limits that are shared amongst all executed code during the course of a runAllTests request and would like to automatically turn some tests off ...
0
votes
0answers
59 views

System.AssertException: Assertion Failed: Expected: true, Actual: false when there's no statement to return true or false

The previous dev person left without leaving any documentation on the Apex Trigger, and this trigger is blocking us from implementing the new process. I check off Activate in the sandbox and am ...
0
votes
0answers
20 views

How to get code coverage for independent if conditions in for loop using test class in salesforce? [duplicate]

I need help to get 100% code coverage for below trigger.This trigger will prevent me creating duplicate record. trigger DuplicateTriggerReseller on Reseller_Details__c (before insert) { for(...
0
votes
2answers
62 views

Can I ignore all the other triggers in a test class?

I have written a relatively simple trigger and I am now attempting to write a test class for this trigger. The trigger is as follows. trigger MapDatesPA on Position_Employee__c (before insert,before ...
0
votes
0answers
72 views

How to update non setup objects in test class

I have a test class where I queried Email template made changes and updated it. While running test class I am getting Salesforce Internal Error. Can someone help me how to fix the issue. //Test Class @...
2
votes
1answer
66 views

Test class getting DUPLICATE_USERNAME error even with unique username workaround

I have a class that creates a user from a contact record, so I uses the Salesforce knowledge article to make sure the email address of the test contact is unique, so it can generate a unique username, ...
-2
votes
1answer
31 views

Invocable Test Class

I'm trying to write test class for one of the Invocable class that calls another class, though the test passes but i don't think it is actually testing the code. Struggling to call list in test class ...
0
votes
0answers
18 views

Test Apex sending mail with .getContent() [duplicate]

I'm trying to write a testMethod to cover a method that is using .getContent(). Here is a sample of code i want to cover global class ExportReport { @future(callout = true) public static void ...
0
votes
0answers
62 views

Error EntityInfo of EntityObject cannot be set to null

I get the following error message: EntityInfo of EntityObject cannot be set to null when my apex test gets to this code: Datacloud.FindDuplicatesResult[] results = new List<Datacloud....
0
votes
0answers
34 views

How Do You Test Multi-Currency Logic?

You cannot setup any currency during apex tests, and therefore any logic that works on the currency of records is untestable. Am I correct? The CurrencyType does not support DML (https://developer....
0
votes
1answer
144 views

Help Writing Apex Test Classes - Knowledge Articles

I'd like to preface this by saying that I'm very new to writing Apex test Classes, and Apex code in general. I found an Apex class from another post here, and slightly tweaked it for my needs. I've ...
2
votes
1answer
48 views

Public variable appears empty in the test method of a test class

I am trying to get the value of the variable "listAccountsTest" in the "static void test" method. This variable will be used in the "System.assertEquals" method as the ...
0
votes
0answers
38 views

Test Class - Never achieve the overall code coverage and always is 0% [duplicate]

I created a trigger for when an incident has the status changed to Canceled, a calculation is performed. I created the test class, but I never get the code coverage to migrate my trigger to production....
0
votes
2answers
22 views

I'm not getting any test coverage below

public class EmailDistributerTemplate { public Id accountId {get;set;} public list<account> getLocation() { list<account> locationadd; locationadd=[select id,...
0
votes
1answer
51 views

Mimic Email-to-Case in a test class

I'm writing a method that marks a case as a "Duplicate" if two or more email2case addresses are referenced in the To Address of the incoming email. However, I can't figure out the best way ...
0
votes
0answers
37 views

Best way of writing tests with lots of stages

So I'm trying to write out a test for our case flows as gradually we have made them more end to end finding spots to split out the tests to avoid hitting limitations is getting harder and harder. I ...
0
votes
0answers
41 views

Method X does not exist in the apex class with Id Y or Method does not exist or incorrect signature: void [duplicate]

I am trying to push my code to production, but I always get 58% coverage which I am not sure sure why since I am testing most of my classes ... Anyway I added one test to improve my coverage but I am ...
0
votes
0answers
39 views

Apex Test class sample [duplicate]

im a newbie in salesforce. can you guys create a test class for this codes below? public class AccountTriggerHandler { public static void methodBeforeInsert (List<Account> accounts){ ...
0
votes
1answer
232 views

How to cover a for loop in Apex Test? [duplicate]

the for loop is not being covered... I would like to know why. Thanks! Here the test: @IsTest public static void testSaveDistriverloren() { Priority_Distribution__c fetchPd = new ...
1
vote
0answers
37 views

Newbie needing help writing a test class for an invocable method

With a lot of help from this forum and the developer forum, I got my first invocable method to work but now I am stuck on writing the test class for it. Here's my invocable method and the attempt at a ...
1
vote
2answers
80 views

Is it possible to use system.runas with the force cli?

Sometimes when creating UnitTests I'm unable to save classes for hours at a time. It'd be great - as a workaround - to develop UnitTests using the "force cli". However, I'm unable to execute ...
0
votes
1answer
328 views

System.TypeException: DML operation INSERT not allowed on QueueSobject

I am trying to insert a QueueSObject in test class but getting the error System.TypeException: DML operation INSERT not allowed on QueueSobject This code was working before but started giving error ...
0
votes
1answer
25 views

testing apex class with custom setting validation

I have this apex class: public class APILogManager { public static Boolean logByEmail(HttpRequest req, String responseHeader, Integer code, String endpoint, String responseContent, String entity){ ...
0
votes
0answers
41 views

Troubles passing Apex superbadge

I wrote unit tests for Maintenance Request and Maintenance Request helper, positive, negative and bulk cases, but I cannot pass the challenge. Any help will be great, thanks in advance.
0
votes
1answer
225 views

AuthInfo error when running apex tests in scratch org

I am having a little practice with scratch orgs and I created two classes which I have correctly pushed to my scratch org with no issues. One of the two classes is a test class. When I try to run the ...
0
votes
0answers
28 views

Test Class covering only 75% coverage .How to increase coverage for this test class [duplicate]

@RestResource(urlMapping='/convertlead/*') global with sharing class LeadConvertRestAPI{ public class ApplicantDetails { public String Application_Id; public String Applicant_Id; ...
1
vote
0answers
68 views

test class fail for LeadShare: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY

i'm doing a test classe and run into an issue with the object LeadShare. So here it is: @isTest public class Test_LeadUtility { @testSetup static void setup(){ String ...
0
votes
0answers
37 views

Can't assign PermissionSet but license is ok

I'm trying to test a class that insert users and assigns a PermissionSet to them. The method works fine in all orgs I've tested it in, however in the test class, I get an error. The error reads : Can'...
0
votes
1answer
31 views

Is it possible to test the "else" part of my apex method?

Here is the code of my method: @AuraEnabled(cacheable=true) public static String getCity() { User currentUser = [SELECT City FROM User WHERE Id = :UserInfo.getUserId() AND City != '']; if(...
0
votes
1answer
26 views

Setup and NonSetup object insertion in Test Class

we've a factory class method to create sObject: Class: DataFactory: public static SObject createSObject(SObject sObj, String defaultClassName, Boolean doInsert) { SObject retObject = ...
0
votes
1answer
21 views

Write a test class to fail the upload AKA get to the catch block

Currently writing a test class to fail the upload procedure but having a hard time coming up with an idea. The only way I was thinking is to make a very big input so that it exceeds the size limit of ...
0
votes
1answer
55 views

Where should the apex tests be located in the LWC project?

I wrote an Apex test (in the Developer console) for a method that is used in my LWC project. How do I upload it to my project in VSC?
0
votes
1answer
17 views

does testing batch class affect non test data

I have a question, I'm making a test class for a batch. This batch deletes custom objects depending on the date (for example, the constructor receives an amount of days, and the batch deletes all ...
0
votes
1answer
26 views

upsert failed, pushtopic with this name already exists

I'm testing a post installation script, but I'm having a problem. depending on the previous version, in my script I do some inserts and upserts of different sObjects. For instance, a PushTopic is ...
0
votes
1answer
34 views

Not able to fix the issue in test class

I have a batch class and I wrote test class for the same. The test class is throwing an error at Date Type. Can someone help me how to fix the issue. Batch Class public without sharing class ...
1
vote
1answer
15 views

Delete Accounts restriction still works in unit tests

The permission to delete Accounts is unchecked in test User Profile according to this trailhead article. https://trailhead.salesforce.com/en/content/learn/projects/protect-your-data-in-salesforce/...
1
vote
1answer
17 views

querying inserted sObjects in test class returning list has no rows for assignment

this is my test class: @isTest public class Test_LWCOrder { private static Order__c order; private static ERPvs__Productos_Pedidos__c pp; private static Erpvs__Envio__c envio; @...
0
votes
1answer
26 views

Process Builder doesn't seem to execute from Test Methods

I have Process Builders built on Cases which makes the following job: Change Owner to Queue on Create Change Status to 'New' on Create, to 'In Progress' on Accept, and changes parent case Status to '...
4
votes
1answer
78 views

Does change set validation run tests within the change set class or the class already in the org or a merged version of both classes?

When you deploy an inbound change set with apex classes and their respective test classes in the change set, does the validation run tests that are in the change set or those already in the org? So ...
1
vote
1answer
36 views

How to test json.deserializeUntyped in trigger

I have a platform event trigger that takes in a json string which contains an array of objects. My postman test call looks like this: "testCodeList__c":"[{\"testCode\":\&...
6
votes
1answer
218 views

Queueable apex runs in System admin mode even after written in System.runAs mode

Queueable class from Test context runs in test runner mode and not in System.runAs user. This is strange behaviour. Here is the snippet. Any idea? User internalUser = // Created Internal User with ...
0
votes
0answers
75 views

What are possible side effects of "Compile all classes" in production? [duplicate]

When I validate a change set with RunLocalTests in production (as well as using the CLI with that flag for CI/CD and packaging integration) there was a class that was erroring out as a dependency. I'...
0
votes
0answers
226 views

Test email sending in Batch class

I have created a batch that sends in email anytime the status of an article is updated. I am trying to write a test class for the batch but I only manage to cover 45% of the class. I struggle to cover ...
0
votes
0answers
11 views

How can I increase my test class code coverage above than 75 % for vf controller apex class? [duplicate]

I am new in salesforce development and I am new in test classes. Now I am trying to increase code coverage for vf page controller. Now it's showing 50% but I need more than 75% .. please any one help ...
-1
votes
1answer
137 views

Error Non static method cannot be referenced from a static context

Test class: @isTest private with sharing class Genereratortest { @TestSetup static void createPayloadtest() { List<_Site__c> studySites = new List<_Study_Site__c>{ ...
0
votes
0answers
25 views

test System field on Batch class

I have a batch that automatically archives any articles with a Status (Fixed) and published for more than 30 days (using a custom setting to verify the number of days). But I struggle to cover the ...

1 2 3
4
5
88