Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
1answer
43 views

What is the life-cycle of static properties in Apex classes?

Sometimes when developing Apex, I've populated some static property. But then later -- most often in an Async or Test context -- I go to access it again and discover SFDC is behaving like it is ...
0
votes
0answers
8 views

Using EvenRelation with Event to assign multiple owners - Test class issues

I have a batch job that counts a bunch of different objects owned/assigned to our Sales Users. One criteria for counting Events is that I need to count Events Owned/Assigned to the user AND Events ...
-3
votes
1answer
37 views

JSON Expected '[' at the beginning of List/Set IN Test class

I am facing below error in test class: Malformed JSON: Expected '[' at the beginning of List/Set Error will throw in below line of the controller: warpList =( List<CaseAssociatedSerExc>)...
-2
votes
1answer
39 views

how to cover code coverage of class for get records from REST API [on hold]

getHousingList() have if() condition which is not covered by my test class @HttpPost global static List<HHSurvey> getHHSurveyList() { RestRequest req = RestContext.request; ...
1
vote
1answer
15 views

LTS and sfdx/developer orgs

I was reviewing the capabilities of the LTS (lightning testing service) and there is a cool sentence in the documentation: Lightning Testing Service can only run in scratch orgs, because tests can ...
0
votes
1answer
423 views

Null pointer exception in test class

I am creating a new instance for a managed object which does not have any mandatory fields in my test class and it is showing null pointer exception in some line of that managed object My code ...
1
vote
2answers
6k views

Test class for contentdocumentlink

Below is the test class that I have written for contentdocumentlink trigger. And its failing to insert the cdl due to insufficent access. @IsTest public class TestAttachmentHandler { static ...
1
vote
0answers
23 views

How add a ServiceReport to a test class

trigger ServiceReporttoSA on ServiceReport (after insert) { for (ServiceReport SR: Trigger.new) { ServiceAppointment SA = [select Id FROM ServiceAppointment WHERE ID =:SR.parentId];...
2
votes
1answer
25 views

Is the Trial-Phase relaxing Test-enforcing and ToolingAPI to save APEX on Production Orgs?

As a great surprise I have noticed today at the org of a new client (his Org is running in the Trial-phase) that APEX Tests seems not to be enforced and that I could modify and save APEX quickly using ...
0
votes
0answers
26 views

Test class for pagereference in a method [duplicate]

I am unable to get code coverage for my pagreference, my code is code: public class selectedcase { public list<recordtype> record {get; set;} public id ids; public selectedcase(){ ...
4
votes
2answers
251 views

Is it possible to invoke test from apex?

If yes, how to do that? Sorry, sounds trivial, but couldn't google it out.
-1
votes
1answer
46 views

Send email failed, No body supplied for file attachment in a batch apex [duplicate]

I wrote a batch apex to send reports. PFB the main class and test class but not able get the code coverage. Please assist me. public class BatchReportsAutoSend implements database.Batchable<...
0
votes
1answer
20 views

Trouble writing Help Class for JSON de

This test class is driving me crazy. I have can prove an array is passing through the class from the test class, but I can't seem to get code coverage. I did use the Json2Apex tool to build the class. ...
0
votes
0answers
29 views

Test class for RequestData class [duplicate]

@HttpPost global static List<HHSurvey> getHHSurveyList() { RestRequest req = RestContext.request; RequestData mRequestData = (RequestData)JSON.deserialize(req.requestBody.toString()...
0
votes
0answers
20 views

Test method for doGet() [on hold]

@RestResource(urlMapping='/getTL/*') global class WS_GetTLList { @HttpGet global static User doGet() { RestRequest req = RestContext.request; User user=new User(); String ...
3
votes
1answer
88 views

testmethod that publishes platform events - GACK 255731747

Use case: Testmethod that invokes a service with more than 200 Sobjects Service does work on each Sobject and as a side effect, also publishes Platform Events By varying the number of Sobjects, at ...
0
votes
2answers
448 views

Tool to extract the Code Coverage in Salesforce

I tried using Aside.io, but the problem I am facing here is that it shows some class code coverage as zero, But if I try to run test class for that individual class it shows as 75+%. Still it shows up ...
5
votes
1answer
53 views

Any way to use sfdx force:apex:test:report to poll?

To work around another problem (EAI_AGAIN errors when pushing or running unit tests in a newly created scratch org from Jenkins CI using SFDX), I'd like to (gently) poll for the test results produced ...
-2
votes
1answer
46 views

Test class for delete method for RESTAPI for Delete

how to write test code for below rest api service global with sharing class Create_HH_Survey { @HttpDelete global static void doDelete() { RestRequest req = RestContext.request; ...
1
vote
1answer
29 views

Test Class for Controller Extension Visual Force Page

I am trying to test my controller extension, Although the final score coverage hit into 100% but when i checked my tests log in my dev console i got Error. This is the ERROR Message: System....
0
votes
2answers
41 views

Test method for request in JSON Format

Malformed JSON: Expected '{' at the beginning of object @HttpPost global static Void doPost() { //Initailizing variables String respString =''; ...
0
votes
2answers
432 views

How to cover the code for nested for loops

Here is MyTest Class Code : @isTest public with sharing class Rfleet_DZBatchProductUpdate_Test{ static TestMethod void getParenetProductValuesTest1 () { Test.StartTest(); ...
9
votes
4answers
186 views

Is MIXED_DML_OPERATION in unit tests broken?

We have a nightly integration that runs all tests and reports any errors against production, currently on Winter '19. Everything was fine until January 14th, 2019, when 13 previously passing tests ...
4
votes
1answer
42 views

Are Apex tests run differently depending on how they are started?

So I have this test Class, when I run the test from inside Salesforce it fails. When I run the test from the Dev Console it passes. Why are the results different when I invoke the test from a ...
1
vote
1answer
28 views

Test Class for the below code

i have written a test class for the following code, but it throwing a error like "Attempt to dereference a null object". can anyone please help me to overcome this. public class leadclass { ...
0
votes
1answer
454 views

test class for trigger on duplicateRecordItem object

I have a trigger on duplicateRecordItem object, which is working fine. I have also written a test class for the same, which is passing, but test coverage is showing as 0%. Can anybody help me out. ...
0
votes
1answer
461 views

Test Class - Controller/Component For Data List Only

I've been struggling for a few days now on this and just cannot find the answer. What I have is a controller that simply passes a list through based on two criteria. The controller is used by a ...
4
votes
3answers
7k views

Compile Error: Method does not exist or incorrect signature: Test.startTest()

I am experiencing something weird on the Sandbox with all the test classes. whenever I run a test class I get the error: Method does not exist or incorrect signature: Test.startTest(). I am ...
0
votes
0answers
20 views

Code Coverage - Salesforce Connect Custom Adapter / Datasource.Connection Class

I am unable to find documentation on or get any code coverage for the customer adapter Apex Class (Datasource.Connection Class). For awareness, the external data source and customer adapter functions ...
1
vote
1answer
42 views

Creating Test Class for Einstein Bot Invocable Apex Class to Search Articles

I've created an Invocable Apex Class that allow us to search articles and return the resolution to the bot. The Apex class works as expected in the sandbox. However, I'm struggling to create a test ...
1
vote
1answer
425 views

how to remove error INVALID_PARTNER_NETWORK_STATUS?

I am getting an error System.DmlException: Insert failed. First exception on row 0; first error: INVALID_PARTNER_NETWORK_STATUS, invalid status for partner network operation: [] In my apex ...
0
votes
2answers
470 views

create test data for opportunityfieldhistory

Please suggest how to create test data for OpportunityFieldHistory. I'm changing the opportunity field(set History Tracking) and updating the same in test class. But the that opp object is not coming ...
3
votes
1answer
24 views

How can I set the data for a report testing?

I have a schedulable class that runs a report and send an email with the results of that report. Everything works fine when I'm testing it with the report filled with data, but when the report is ...
0
votes
2answers
2k views

Test not cover the execute method in batch

I'm trying to search in enternet but no results.... So i haveing a batch that updates records (IT_Asset__c) if the FrstDayOfMnth__c = true. After that fires the trigger. The apex test class not ...
3
votes
1answer
4k views

Test Class not covering the execute method

This batch class is to set the recordtype when it is null. global class ContactBatch implements Database.Batchable<SObject> { global String query; global Database.QueryLocator start(...
1
vote
2answers
450 views

Code Coverage for Custom Object HISTORY

I have method in controller class to get the history of the fields to show it in a detail page. But history details are not able to cover in test class. I have enabled Field history Tracking in object....
3
votes
1answer
461 views

Testing @future method Failed Assertion

I have some code that after inserting a task, calls an @future method to update some fields on the contact linked to that task (WhoId). This seems to work fine in sandbox, but I can't seem to get it ...
5
votes
2answers
642 views

@testSetup method and System.CalloutException: You have uncommitted work pending

Apologies ahead of time for the lengthy post, but I'm receiving the following error when attempting to run the test method below. The error occurs when the upsertProject method is called. System....
1
vote
0answers
13 views

Having trouble accessing updated Contact.Histories in unit test [duplicate]

I have a custom object to manage patient (Contact) status changes, which affect product shipments. I'm adding a process to roll back changes based on receiving a cancelled form, based on a common ...
2
votes
1answer
53 views

Can't update record in test method

I'm trying to make a test class for an Apex class that runs a report and add functionality for it (send some emails and stuff). The problem is that I need to add records (contacts) for that report to ...
0
votes
1answer
27 views

Apex Unit Testing List<Case>

I have a method public static List<Case> findCase (Id recordId) that returns List<Case> details. I wrote the following Test and it passed. List<Case> details = ...
0
votes
1answer
26 views

Test Class Issue Standard set Controller Class

I write a test class to cover standard set controller class on account but i am not able to pass id. thats why not able cover code coverage. here is my code @IsTest public class ...
0
votes
1answer
28 views

need help on writing test class for controller

i have controller for vf page, i have written a test class. test class is having two methods where i am succesfully able to run the test for Autocal but for Save method i am getting following error ...
1
vote
1answer
20 views

Tests passing with zero code coverage [duplicate]

It seems like literally every test I write is passing with zero code coverage org wide. I've spent the past 2 days on and off reading forums, doing trails and debugging. Below is an example of one of ...
4
votes
1answer
502 views

Why are no results returned when performing a SOSL query on ContentNote in a Test Method?

Following the example laid out in Adding SOSL Queries to Unit Tests, I created a test method that inserts a ContentNote record, sets the results using Test.setFixedSearchResults(), and then performs a ...
0
votes
2answers
56 views

getting error while running a test class,error,Insert failed. REQUIRED_FIELD_MISSING

My controller class is public class Iapc { public boolean detailpage{set;get;} public boolean show{set;get;} public boolean hide{set;get;} public boolean editpage{set;get;} ...
-1
votes
1answer
36 views

Test CLass code coverage problem

trigger Updaterelatedoppty on Account ( after update,after insert , before insert,before update ) { //before trigger if(Trigger.isbefore ) { for(Account acct :Trigger.new){ ...
1
vote
0answers
22 views

Create Knowledge article with channels in apex test code

We have a use case where we expose knowledge articles to customer community users and I'm trying to write test code for that. The problem I am having is that whenever I query for articles using ...
0
votes
1answer
33 views

Is there a better way to create related records when creating test data?

I am trying to create a large set of test data along with child records and this is what i came up with. Could anyone let me know if there's a better way to achieve the same? Integer countStart = ...
0
votes
0answers
32 views

I have Written a class and its test class and but the code coverage is only 11% how can i achive max code coverge [duplicate]

global class UpdateExchange_Rate_Advanced_on_Oppty implements Database.Batchable<sObject>,Database.Stateful,schedulable { public String query; global ...