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

Apex Test class code coverage [duplicate]

Not getting coverage on these line of code, can anyone help with the test class? @AuraEnabled public static Boolean deleteRecord(Id recordId){ Sobject sobj = recordId.getSObjectType().newSObject(...
0
votes
1answer
113 views

Apex Test coverage on External Objects

How can the Test Coverage can be fulfilled for the Apex classes which queried for External Objects.I have written Test class just like assuming External Object behaves like a custom Object but getting ...
1
vote
1answer
265 views

ShowToastEvent is not working for jest test class

MyLighingwebcomponent <template> <lightning-card title="Custom Search Functionality in LWC" icon-name="standard:account"> <div class="slds-m-around_medium"> &...
0
votes
1answer
46 views

Deployment of destructive changes to production and tests execution

We need to remove trigger and apex test class for it from production org. We've already put together destructiveChanges.xml and are going to deploy it to prod org via ant migration tool. The question ...
0
votes
1answer
25 views

Static method cannot be referenced from a non static context - Test Class

I'm trying to write a test class for this class but not sure how to provide code coverage for what I'm doing here. In my class I'm just running a query, looping through the query and creating a list ...
0
votes
2answers
60 views

My apex class code coverage is showing zero percentage on writing the test class

Apex class: public class GenRangoTarjeta_cls {// OJCB v 1.4 This class generates a range of cards concatenating the program code and country code public static void addRangoTarjeta (...
-1
votes
1answer
33 views

Error: Compile Error: Invalid bind expression type of Schema.SObjectField for column of type Id at line 10 column 46

@isTest public class SharinPixWorkOrderTriggerTest { @isTest public static void testSharinPixWorkOrderTrigger() { WorkOrder fieldVisit = new WorkOrder(Job_Name__c='Visiting Green ...
0
votes
1answer
23 views

Test Class For FinishURL StandartsetController

I have an APEX class that ends with a finishURL method; this class is the controller-extension of a VF page. What they all do is to collect the IDs of the selected items on a related list view, then ...
0
votes
0answers
32 views

system runAs method to verify if the user can access a record

I have below test class which verifies whether a use have access to the record or not. The Campaign__C object's sharing setting is Private. However with below test class when I run the SOQL the 2nd ...
1
vote
1answer
61 views

Test method fails with “Attempt to de-reference a null object” but code in class runs

I'm getting System.NullPointerException: Attempt to de-reference a null object when I run the test class, but the batch class will run without any issue. Here is my batch class: global class ...
-2
votes
1answer
38 views

Test class fails to call the method

can someone help me to find the cause why my test class doesnt cover the method that is called in the test class, as seen in my test class I create an instance to call the method from the class. But ...
0
votes
1answer
53 views

In test class can see all org users in list

I have written one query in test class for fetching users,as per my understanding query should return the user records created in test class only,but its giving all user from salesforce org.is that ...
0
votes
1answer
47 views

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ContactTrigger: execution of BeforeUpdate

I am getting the following error in my test class. The insert tests work fine but the update test is failing. Error: 20:02:22:421 FATAL_ERROR System.ListException: List index out of bounds: -1 20:02:...
0
votes
1answer
32 views

Trigger Testing Issue

Im just fleshing out the logic here before tiding it up. For the life of me I cannot figure out why this isn't working. The Primary__c is being changed in the trigger but it is not asserting that is ...
1
vote
0answers
32 views

Callout Exception when testing

I use a webservice to validate government info on companies. This is used for accounts and Cases. For some reason I'm getting this calloutException but there's no DML before the callout. I'm getting ...
0
votes
1answer
34 views

Apex: Use one test class in another test class

I am working on some email automation and I have a separate test class for each language, kind of like this: @isTest public class EnglishEmailTest { @isTest public static void test1() { .....
5
votes
1answer
324 views

Mocking CurrentPageReference wire in Jest unit tests - LWC

I have a LWC component which uses CurrentPageReference from lightning/navigation bundle in a @wire function. I am using lwc-jest to create unit tests for my components. Using the wire with ...
1
vote
0answers
24 views

How to test whether a Platform Event Trigger throws an unhandled exception

Since platform event triggers are run asynchronously, an error in processing them doesn't cause the test method to fail by itself. So, how would I write a test that under certain circumstances, my ...
0
votes
2answers
39 views

Unable to access versionData from test class

I am facing an issue but I don't know what I'm doing wrong. I'm writing a test class for a code which has this 2 lines: public static Blob getPkpass(){ // more code here... List<...
0
votes
0answers
51 views

How do you create Resource Calendar in Apex for test class?

I need to have a Resource Calendar in Apex test class. I tried to do below in Test Class. List<Calendar> lc = new List<Calendar>(); for(Account acc :listAcc) Calendar c =...
1
vote
0answers
33 views

UI Theme Detection: Unit test code coverage

Since Winter '16, we have had the ability to add conditional logic to our Apex controllers and Visualforce pages based on the UI theme the user is currently working with (i.e. Classic vs. Lightning ...
1
vote
3answers
83 views

How to cover Catch block in ApexUnitTest class when using DML statement in try body

I have some apex code, where I try to upsert a list of records: try { upsert recordList Accounts; } catch (DmlException e) { //do a loooot of stuff in order to provide a proper ...
1
vote
1answer
56 views

How to test an inner class?

I did my research, but could not find a clear guidelines on how to test an inner class. This is my inner class: public class ExistingAccountResult{ public String salesforceaccountid {get;set;} ...
-2
votes
1answer
40 views

how to write a test class for web service HttpPost

I'm new to development here I'm developing a webservice in rest and I have no idea about how to write a test class for that. Please find the below code of apex class: @RestResource(urlMapping='/...
0
votes
1answer
95 views

Creating test class for apex (reports namespace) used in Flow action

I have a Flow which calls an apex class (via action). The purpose of the action is to grab a list of Lead Id's from a specific report. The reportID is passed to the class from the flow. Then, the ...
0
votes
0answers
53 views

Need Help with a test class to my apex class that attaches a Visualforce Page pdf to the quote [duplicate]

I found a way to write an apex class that attaches my quote which is generated by an vf page as a pdf to my quote object. Writing the test class is even a bigger problem for me. I get to 36% coverage ...
0
votes
1answer
29 views

ContentSize in Test Class

I am writing a trigger that deletes files/attachments smaller than 5 KB assigned to email messages. I read on this post that the field ContentSize on ContentDocumentVersion is not writable. My ...
-1
votes
1answer
33 views

Code coverage for delete statement in batch class [duplicate]

How can I get increased coverage for this code? I get only 75% so far. Not able to cover the delete statement in the main class. Any help is greatly appreciated. Main Class: public void execute(...
0
votes
2answers
156 views

Test/API Difference with Regards to EmailMessage and Messaging.SendEmail()

Any resources on what might've changed in API 37 that wasn't present in 36 that could be causing the issue I'm seeing? If I update every other apex class in my org to 46 and leave the test class at ...
-1
votes
1answer
48 views

Test method with not writable fields [closed]

Please help me test the method because I'm at a dead end. It does not return anything, but sets values ​​to two custom fields subject to several conditions. Half of the method is covered by tests, ...
0
votes
0answers
27 views

Test Class for Page Reference Method Help [duplicate]

I'm not sure where to get started with writing this test class. I'm a junior developer and when trying to test createCourse PageReference method I get either an insert or assert fails, or I get an ...
1
vote
0answers
30 views

Testing custom salesforce plugin

I am currently trying to test a custom salesforce plugin which deploys a payload to a specific org. The plugin itself is coded in typescript and the unit tests are using mocha/chai. I am running ...
0
votes
1answer
17 views

Code Coverage Failing

I have tried this multiple ways with no success. I have a controller class that I need to write a test class for. I have written the test class, and see that the test method passes. However, when I ...
0
votes
3answers
36 views

Test cases in a list

I am trying to get code coverage for my list/loop but no matter what I try I am missing something and could use a hand if possible as I am trying to learn more about Apex. Trigger: trigger ...
0
votes
2answers
62 views

Problem. Method does not exist or incorrect signature

Please help me fix my test. @isTest public class TestProductTableApplication { @testSetup static void setup() { ProductTable__c product = new ProductTable__c (Name = 'carrot', Price__c = 10,...
1
vote
1answer
25 views

Setting locationId in Asset

I am working on test class of trigger of Asset. I need to add location to the Asset object. Have created the test class like below: @isTest( seeAllData = false ) private class AssetTriggerTest { ...
1
vote
1answer
203 views

Failed to enqueue tests.: An unknown exception occurred

While running unit Tests in my Sandbox, i got the Following Error and i cannot continue with tests. Message is: Failed to enqueue tests.: An unknown exception occurred. Any ideas ?
1
vote
1answer
244 views

Lightning Web Component unit testing with get record and conditional rendering

I'm trying to test a component that shows a button if the record my component is sitting on has a certain field populated, but I can't get the tests working: the button is always created, regardless ...
1
vote
1answer
55 views

Can we use custom assert methods in Apex tests?

Sometimes I need to check order, size of the list, fields of elements. Standard methods (assertEquals, assert, assertNotEquals) are too simple, so I build similar lines in //then part of the tests. I ...
2
votes
2answers
43 views

Writing tests that require multiple versions of custom data

OK here is a real fun one. I need to write tests that cover code that queries for custom metadata types. The code and test will be deployed to many different salesforce organizations which will ...
0
votes
2answers
47 views

Setting Invocable Variable value for a Test Class

I'm having difficulty finding a way to write the syntax to set my invocable variables in the test class: Here's the code. global class EmailPreventivoAccettato { global class Parametri { @...
-1
votes
1answer
135 views

System.Assert for the method with Void return type [closed]

How we can write system.assert statement for the method returning void.
1
vote
1answer
41 views

How to test a static void @HTTP method that creates custom metadata

Here's a fun one...I have a static @HTTP method creating metadata as a webservice. You can test metadata deployment containers, though not the actual deployment, as shown here, but apparently only if ...
2
votes
1answer
69 views

How can I write a test that involves accessing the EmailMessage.ActivityId field?

I have some code that involves the following SOQL query: EmailMessage emailMessage = [SELECT Id FROM EmailMessage WHERE ActivityId =: task.Id]; In order to write a test for this code, the test setup ...
0
votes
1answer
49 views

Error While updating the Owner of the Case to queue Id

Hi I am having the scenario where i need to update the owner of the case to a particular queue. but i am getting the error as below : System.DmlException: Update failed. First exception on row 0 ...
-1
votes
1answer
169 views

MOCK test Class for POST web service test class

Hi I am new to integration i need to write the Mock Test class for my webservice test class, i am stuck , please help me to create the mock call out in the APEX Below my class: public class ...
0
votes
1answer
26 views

Question Concerning making a Test class for a before update trigger that sends an email

I'm currently trying to make a test for an apex trigger that sends an email if a certain donation field has been changed(before this I tried using a workflow but for some reason it did not work). From ...
0
votes
2answers
82 views

How can I assert that a map has the values needed?

if anyone could help; I'd appreciate some guidance on a test class I am working on. I am new to Apex and I am trying to test a class that uses a map which is the only piece of code I need testing for. ...
1
vote
2answers
35 views

Single Email Limit Exceeded

I am hitting an apex error in production: "SINGLE_EMAIL_LIMIT_EXCEEDED". I have unit tests in production that run when I do the deployment that call methods as part of the test that send out email ...
2
votes
2answers
177 views

How to use Limits.getCallouts() in a test class for a callout in a future method

After a bunch of research, it appears this is not possible, but I'm hoping someone here has found a way. I am using a before update trigger on Opp to call a class which contains a future method with ...

1 2 3
4
5
77