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.

1
vote
1answer
115 views

Unit testing with SOAP and REST callouts

My project assumes quite big integration with external webservices. Unfortunately first major service is SOAP and second is REST. Problem is that there are getting more and more places in the code ...
0
votes
1answer
58 views

Calling rest resource (Post) within the test class

I am working with a supplier who proscribes DML operations on its application's objects. Instead, they ask us to call Rest resources in our org that they developed in order to interact with the data. ...
0
votes
1answer
44 views

Test class shows Unexpected Token 'By' error

How to pass the value for following test class public static Result[] lookup(String searchString, String sObjectAPIName, String whereClause, String whereClauseType , String whereClauseValue, String ...
2
votes
1answer
90 views

Test Class failing in production [closed]

I have a test class failing while validating it and its base class deployment to production. The test setup is creating several records in 2 objects (1 standard 1 custom) and inserting them as a ...
0
votes
2answers
112 views

Test class problem for below apex web services class [duplicate]

I'm trying here to write a test class for below apex class, I'm getting the below error when in the compilation: Methods defined as TestMethod do not support Web service callouts Test class: @...
0
votes
2answers
209 views

Apex test class method issue

Here I have @Auraenabled apex class I'm trying to write a test class but it's throwing an error like below Static method cannot be referenced from a non-static context: List<AuraSampleController....
0
votes
1answer
110 views

test class coverage for return statement

How do i cover code coverage for a return statement.I am not using pagereference. if(atleastoneselected==false){ errMsg='No contacts Selected';//not covered return page....
0
votes
1answer
36 views

Can I deploy to production without validating my change set?

Am I able to deploy an inbound change set to production without validating it? I know it is best practice but I can't get the unit test to work as I am getting the following error in my test. ...
5
votes
0answers
209 views

System.UnexpectedException after catching an exception in unit test

I've encountered an odd situation where the presence or absence of a try/catch block results in an unusual system error: System.UnexpectedException: Error processing messages The test case is ...
-1
votes
1answer
34 views

Running testclass for my controller class [duplicate]

Hey any help how to create a test class for codes public class MycustomSettingController { public Org_Info__c orgInfo {get; set;} public MycustomSettingController(){ orgInfo = new ...
11
votes
2answers
79 views

Why does filtering by a Owner Id and Owner Type fail in unit tests?

I wrote a class that needs to query for "cases owned by the current user or in a queue", and so I wrote this seemingly normal query: Case[] cases = [SELECT Id FROM Case ...
0
votes
2answers
29 views

Test Coverage Help - Insert Custom Object But No Test Coverage

Hopefully this will be an easy one and I am just missing something small. I have a method queries for a custom object. My test class isn't seeing the custom object I have created in the test class. ...
4
votes
0answers
47 views

Perform a deployment and execute all tests with a flag to opt out of collecting code coverage

I'd like to perform a deployment and execute all tests with a flag to opt out of collecting code coverage. The goal is to speed up Apex test execution. I'm aware that we can do it manually by ...
5
votes
2answers
91 views

Salesforce Test accesses some org records

I'm bit new to SF. I have problem with one of the tests. Basically I create an empty test and check if records are empty. But whatever I do, ContentNote records are not 0. When debugging, I saw that ...
-3
votes
1answer
35 views

Need help for writting test class for method for extention controller [closed]

Sorry I am new with salesforce developer. I have written method for extension controller. I need help with writing test class for that method. with that method what it does is visualforce is renderas ...
0
votes
1answer
50 views

Test Class for a Custom Controller

How do you make a test class for custom controller? My search results involves this but trying to apply it in my test class only create too many error that I don't understand. public static ...
1
vote
1answer
32 views

Test Class for a Class that only performs dml and query

I'm new to Salesforce. Creating Test class for a trigger isn't as tough as creating test class for simple class that only has a dml and a query. The line "clInfo.GetAll();" is giving me 100% code ...
0
votes
1answer
29 views

Custom Settings in test classes for Lookup fields(ID)

I have a custom setting where I store Id's for my dock records. (Dock__c) In my test class after "creating" the custom setting and my other records, how can I reference the custom setting to match my ...
5
votes
1answer
532 views

What is recommended way to unit test JSON Parser based on JSON.deserializeUntyped calls?

We are doing a lot of JSON data parsing in our solution by own JSON parser implementation. I wonder how can I write unit tests for JSON parser. Is it good approach to load JSON data from static ...
0
votes
2answers
34 views

test class help for apex function

I'm pretty new to writing test classes and I seem to be stuck here. Please can you point out the issue? Function: public static void UpdateCaseRegionCode(List<SObject> listOfNewSObjects ){ ...
0
votes
1answer
29 views

Test Strategy for managed packages

I would like to check if my understanding is correct and also would like some help in how to handle a particular scenario with test case executions. I have been writing test cases for all the Apex ...
-2
votes
1answer
38 views

How to increase code coverage?

My test class is passed but test coverage is 0%. Can any one help to increase tets coverage: APex Class: public class TopicOfInterestUserAsgmtDataAccessor implements ...
0
votes
1answer
112 views

SOSL not returning any result in Test class

Test Class static testMethod void testBehavior() { User objUser = [SELECT Id FROM User LIMIT 1]; System.runAs(objUser) { String strContactId = String.valueOf([SELECT ...
0
votes
2answers
29 views

add two numerical values from soql and show on visualforce page

I want to add actTotalAmount and purTotalAmount and show it on the visualforce page. Right now I have another fuction to show actTotal and purTotal on visualforce page, but I couldn't find a way to ...
4
votes
1answer
72 views

Test.createStub for class which returns Batchable in method

I believe I've found a bug, but I wanted to throw it to the community to see if I'm not understanding something. I'm implementing a test class and using Test.createStub to mock a dependency. The ...
0
votes
2answers
74 views

Test Class Only Covers the Callout Method but the rest of the methods isn't

I have Mock callouts in my test class but the test class didn't cover some of the codes. It has been solved before but there were changes to my code and now my test class isn't working. The scenario ...
0
votes
2answers
26 views

Test classes deployment code coverage

If I am deploying test classes from sandbox to production, how does Salesforce calculate the code covergae? For example: If I have 5 classes with 5 test classes, should the overall average coverage ...
5
votes
1answer
121 views

Is it possible to configure currencies in a multi-currency scratch org?

I'm writing SalesforceDX unit tests that need to use either USD or EUR in Account.currencyIsoCode. So I created a scratch org from this project-scratch-def.json configuration that specifies the ...
-3
votes
1answer
31 views

Test class coverage help when using if statement

I am having trouble testing each condition of the do_init method in the test class and I am thinking I have some sort of scoping mind block. How can I write the test class to test each condition? I ...
0
votes
1answer
36 views

Need help on how to cover this query filter criteria in batch apex test class

global class BatchUpdateEnrollmentState implements Database.Batchable < sObject > , Database.AllowsCallouts, Database.Stateful { public String query; global Database....
-1
votes
1answer
78 views

Test Class for Trigger Null Pointer Exception

I am new to apex. Getting this error System.DmlException: Upsert failed. First exception on row 0 with id aBfn000000062BMCAY; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OP_DeferralTrigger: ...
1
vote
1answer
75 views

Using Parallel Test annotation for Apex mocking framework

Currently in my org there are around 50 test class which just uses Apex mocking framework and has no interaction with database. I have other test classes that is actual Apex test classes(around 1000+)....
-3
votes
1answer
217 views

How to write a test class for dynamically running multiple Callouts [closed]

This is my apex class, please help me in writing a test class for it.Thanks global clas LoginClass{ public string Cookie_M; public string Session_M; public string Token_M; public string Username_M; ...
2
votes
1answer
45 views

Test classes and foreign key constraints

Here's a simple test class that illustrates an issue I'm having with a test class that I have been putting together: @isTest public class ForeignKeyConstraintTest { @isTest public static ...
1
vote
1answer
232 views

How to Test Omni-Channel User Service Presence in Apex Test Class

I have a class I need to write an apex test class for that uses the UserServicePresence object for Omni-Channel as a major filter for a SOQL query in the class. The majority of the logic in the class ...
-1
votes
1answer
37 views

unable to cover batch class completely [closed]

Scheduler Class: global class bankerjob implements Database.batchable<sObject> , Database.Stateful{ private EmailTemplate emailTemp; global bankerjob(){ emailTemp = [Select Id From ...
0
votes
1answer
66 views

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY in testclass

@isTest Public class BureaucracyFeedbackDetailscontrollerTest { public static testmethod void mytest1(){ Test.StartTest(); Community community = [ SELECT Id FROM Community WHERE Name = '...
0
votes
2answers
48 views

Not getting the oldvalues in test class - trigger coverage

I have a test class where i am updating the stage to cover my test class. Issues is i am not getting the old value in after update trigger All my debug are with new value :( Below is my trigger ...
4
votes
1answer
1k views

What should the negative tests include?

While preparing myself to the Developer 1 certification I met the following question: A developer is asked to write negative tests as part of the unit testing for a method that calculates a person's ...
0
votes
1answer
76 views

Covering addError in test class

I built this error to fire off an exception when an account's SLA field with open cases is being changed, when it shouldn't. Trigger trigger DoNotAllowSlaChangesWithOpenCases on Account (before ...
1
vote
1answer
120 views

Lead Conversion Trigger Test Failing

I have the following trigger that is working properly trigger LeadConversionTrigger on Lead (after update) { for (Lead l : Trigger.new){ if (checkRecursive.runOnce()){ // only run if ...
0
votes
1answer
55 views

How to pass record id from row to Test method?

I delete 1 record from table. How to pass into test method selectedMR(this record Id) and cover in test method from controller below? VF PAGE: <apex:repeat value={!mrItems} var="mrItem"> <...
-4
votes
1answer
25 views

Looking for a Test Class for code coverage [closed]

I have created an Apex Class and VF page for Popup Alert. I am looking for a test class for the same. Below is my Apex Class: public class PopUpAlert { public Contact cont; public PopUpAlert(...
1
vote
1answer
28 views

Unable to cover code for aggregate results function

here I am trying to cover code for aggregate function. Here I am providing class code and test class, anyone have any clues why unable to cover. public class ChartdataCon { public Integer ...
-3
votes
1answer
53 views

How to cover delete part in testclass

In test class,Following Lines are not covering. Attachment: But I need to cover Those two lines as well.I'am doing some mistake for covering those two lines, can anyone Please help me to ...
0
votes
0answers
44 views

Test Roll-Up Summary field with MIN Decimal for Data calculating

I tried everything in this test and I really don't know, how to do that right. It's 3 Objects: A has a Number (Decimal) field. B has a Lookup field to A, Master-Detail to C and Number field for ...
-2
votes
1answer
40 views

How to add new line in system.assertEquals

How to add new Line in System.assert statement Actual result in UserInterface 1.Client Stability Risk & Mitigation: Test Risk1 2.Contract Terms Risk & Mitigation: Test Risk2 How to add ...
0
votes
1answer
34 views

How to do better usage of system.assertMethods in Test class

I'am working on Test class it has code coverage as well. I used system.assertEquals statements,But anyone can please help me to use better system.assertmethods in below scenario with Proper ...
1
vote
1answer
72 views

Apex Web Services Trailhead: Need 100% Code Coverage

I can't seem to figure out how to reach 100% code coverage. Currently, I'm at 80% and the "return acct;" is the only thing that is not covered. Could somebody help me figure out how to test this? The ...
0
votes
1answer
128 views

creating test data for network object

kindly let me know how to create the test data for the network object in test class. Below is the class and test class, kindly help. There are no methods only constructor code, apart from some ...