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
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 ...
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 ...
-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>)...
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 ...
-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
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(){ ...
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()...
-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
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 ...
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. ...
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 ...
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 =''; ...
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 { ...
-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; ...
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 ...
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 ...
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 ...
-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){ ...
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 = ...
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
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 ...
0
votes
1answer
16 views

Testing the Response of a PUT Method (or an response really)

I have a PUT method that I am attempting to test, but, like usual, APEX's ridiculous restrictions are causing roadblocks at every turn I make. My put method works fine when I am calling it from ...
2
votes
2answers
29 views

Accessing Variables from a Parent Class

I am attempting to set up tests for my APEX classes, more specifically, I am attempting to create a parent class that includes a prepareDatabase function that creates data for my tests, and this ...
0
votes
0answers
15 views

Test execution causing Eventbrite error in 'Eventbrite OpportunityTrigger'

Facing issue in my batch test class. I am inserting simple Account and Opportunity in my test class. If we set(seealldata = false) the class fails in the sandbox and getting below error System....
3
votes
0answers
20 views

Creating BigObject Record in Test Class Using Test.loadData(..)

Successfully used testLoadData for a number of test classes for "regular" Sobjects. Have seen references to Stub Api Mocking Framework for one method to create test records for Big Objects in Apex but ...
1
vote
2answers
32 views

Deploy test for a SandboxRefreshScript

I'm trying to deploy a SandboxRefresh script to prod. One of the main things that script does is replicate the structure of Chatter groups we use so that I can then use Processes in my sandbox that ...
0
votes
2answers
26 views

Method does not exist or incorrect signature invocable

Asked and answered here many times but I'm not finding this scenario. Getting method does not exist error when trying to invoke this Apex Class in my test. global with sharing class ...
3
votes
3answers
28 views

Trigger unit test or integration test

I have written some apex triggers along with some classes. The triggers are quite small because all the real work happens in the classes. trigger MyAccountTrigger on Account (after insert, after ...
0
votes
1answer
50 views

I am not able to pass values into Custom settings fields in test classes?

There are Three custom objects Property__c Fields: Name, Region__c, site__c Deal__c Fields: Name, Type__c,Manager__c,Property__c Project__c Fields: Name, OwnerId,Deal__c // all objects has master ...
-2
votes
1answer
68 views

Apex test failure for one of the method in the class

We made a very minor change to the apex class where we included a field in the Email mathod in the class, however when we tried to deploy we get attempt to de-reference null object error. Test class: ...
5
votes
1answer
72 views

Test coverage for a relative date method

Newbie coder here, so I could use some help with test coverage. I've got a class for creating test/training data in a sandbox. At the beginning of that class, I've got a couple of utility methods to ...
-2
votes
1answer
39 views

Test Class approach Help on Custom Object (Query and Update)

I have an Apex class on Custom Object Called QueueDistroHelper__c What I am basically doing is getting the Queue Id from a custom field(Related_Queue_Id__c) on the Custom object Querying all the ...
-1
votes
1answer
17 views

What will be the Test Class for this Pie Chart? [closed]

public with sharing class PackageBuilderExtenssion { public PackageBuilderExtenssion(ApexPages.StandardController std) { sc=std; id=std.getId(); //Controller Id ...
0
votes
1answer
21 views

Variable does not exist: Quantity

Variable does not exist: Quantity Although it does exist as I added a value to it and it worked fine this is the code @isTest public class AssetTriggerTest2 { @isTest static void test(){ ...
-1
votes
0answers
16 views

I want to create a test class using this code,.Anyone help me in this one?Thanks [duplicate]

public class AccountSearchController1 { //main class //results variables public Boolean hasResults{get; set;} public List<accountSet> resultSet {get;set;} public List<...
0
votes
1answer
35 views

Test Class for Comparable Wrapper class

I am trying to write a test class for a Comparable Wrapper with little success. The wrapper class pulls in two objects to make one single list. I have two issues... I don't know how to cover the ...
0
votes
2answers
25 views

Inner Class Cover in Test Class

Please help me why my code coverage is showing 0% . See my class code and test class code where I have written wrong? Class public class InnerClass { public class Wrap { public string ...
1
vote
2answers
38 views

Cover Error Handling on Test Class

I am having an issue where I have a trigger that rolls up data from contacts to an account. This was working fine with no issues until we added a managed package app that is constantly checking and ...
0
votes
1answer
25 views

How to insert a dummy value for custom metadata setting

I have a batch class and in the constructor of the class, I have a query in which it queries for a Queue. Constructor: public BatchClass(){ final String QUEUE_NAME = GlobalPropertyCache.getValue('...
0
votes
2answers
42 views

How to assign both (value, label) to picklist field in Unit Test class?

Added explanation: Since the Case.picklistField is constantly modified by other Org user (non-developer), so I want to avoid data dependency as much as I could. I have a case trigger method using ...