Questions tagged [failing-tests]

A unit test is code that is written and executed to test a specific portion/unit of source code. Tests that do not pass are considered failing. Tests that do not generate desired coverage are still considered to pass.

Filter by
Sorted by
Tagged with
17
votes
2answers
2k views

Test.setCreatedDate fails on note record created in test context

I'm trying to get a number of records inserted into the database sometime in the past, to allow for a cleanup batch to have proper test coverage. I can use Test.setCreatedDate on the account I'm ...
17
votes
4answers
8k views

How to handle installed Managed Packages failing tests?

I have several AppExchange apps installed that are failing tests. What is the recommended approach to resolving this? Are tests run when a new package is installed? Is there a way to determine what is ...
14
votes
2answers
652 views

Salesforce 2020 release has blocked all Apex tests that use http mocking

We have 100+ tests failing now that our main testing sandbox has received the 2020 release. We can no longer deploy. We're getting many errors like Unexpected error: You have uncommitted work ...
10
votes
1answer
6k views

Calling addFields in Extension class works on page, fails in test class

I've got a class which acts as a controller extension. The class is designed to add a number of fields to the StandardController so a component used on the page can dynamically access some fields. ...
9
votes
1answer
310 views

How to set both onInstall and seeAllData to true for a test method

I tried to set SeeAllData = true for the test method with OnInstall = true. But I was not able to save the test class if I use "@isTest(OnInstall=true,SeeAllData=true)", so I saved it with "@isTest(...
8
votes
1answer
145 views

Set.retainAll () on API 45 dies with UnexpectedException

I have a weird issue, can somebody help? On API 45, the following test crashes with FATAL_ERROR System.UnexpectedException: java.lang.String cannot be cast to apex.bytecodeinterpreter....
8
votes
1answer
434 views

Custom settings and parallel test execution

I have a bunch of unit tests in which I'm updating my custom settings object to test certain workflows. This causes an UNABLE_TO_LOCK_ROW exception since multiple tests are updating the values ...
7
votes
3answers
1k views

After winter 16 upgrade, started receiving error for test failures while deployment:Methods defined as TestMethod do not support Web service callouts

Our org got upgraded to winter 16 last Friday October 16. When I used to run all test few tests were failing with error: Methods defined as TestMethod do not support Web service callouts however, now ...
7
votes
1answer
558 views

Test class passes in MavensMate, but fails in Apex Test Execution

Basically subj: Some of my test classes pass when I run them in MavensMate, but fail when I run them in Apex Test Execution in the org itself. MavensMate: Apex Test Execution: And just because I ...
7
votes
1answer
3k views

How to create Report (not report data) in Apex Test Class without using SeeAlldata=True?

Joint Report is not supported in lightning.So in our org we have an existing reports in which we pull the data from it and pass it to lightning components so that lightning we can show joint reports. ...
7
votes
3answers
2k views

Testing scheduled apex: CronTrigger does NOT fire after Test.stopTest()

EDIT for clarification of title: CronTrigger is probably actually firing at some point in the testing process - what is wierd is that CronTrigger.TimesTriggered is NOT incrementing after Test....
6
votes
1answer
15k views

Assign a case to a queue in Apex (Test class)

I'm sure this must be quite possible, and probably easy. I need to create a test method in which part of the scenario is that for when a Case is assigned to a Queue. I have successfully tested all my ...
6
votes
1answer
143 views

Unit Testing problem with Product2 records: A Product with this SKU already exists

I'm using the Product object and store the product sku within the StockKeepingUnit field. According to the Winter 18 release notes, this field is considered unique, which is totally fine and expected ...
6
votes
0answers
169 views

Why inserting a user object and making callout in a test throws CalloutException in Production?

I stumbled upon strange behavior when executing tests on deployment to production organization. In the test, I first insert a User object, some other objects and then as the last one, a CampaignMember ...
6
votes
0answers
2k views

error from test method - “apex job is already scheduled for execution”

I have a batch apex which starts itself after x mins. this is done in finish() method using , system.scheduleBatch() method. below is how the batch looks like, global class my_ProcessPurge_Batch ...
5
votes
2answers
2k views

How do I create Test Data for an Org. Wide Email Address?

I need to create an Org. Wide Email address for my Test Class, and I can't seem to find documentation for this. One forum led me to believe it wasn't possible, but it wasn't clear if I was ...
5
votes
1answer
480 views

Is it normal to tests not be able to create queues because there's one with the same name on the organization?

If I have, for example, in production a MyQueue queue, with the same DeveloperName, and I'm trying to run a test class to deploy a change set, which contains a test that inserts a MyQueue queue as ...
5
votes
2answers
688 views

Why is my After Delete Trigger test class failing?

I have a trigger set up on the Account object for After Delete. We have an Affiliates table that has a lookup field to Account. If an Account is merged, I don't want to delete an Affiliate. It will ...
5
votes
0answers
62 views

Test fails with runAs, queueable and callout in specific org

Has anyone got an idea what could cause the following test to fail in one org and pass in another? The error is System.CalloutException: You have uncommitted work pending. Please commit or rollback ...
5
votes
0answers
381 views

Difference between deploying user and System.runAs()

I have a weird situation where some test classes will deploy to Production only if the user deploying it has a specific keyword on their LastName - "TestMode, TestsEnabled". Updating my test classes ...
5
votes
0answers
843 views

Process Builder causes Apex Class Test Failure - Stops Migration

My searching for this only displayed a solution which wasn't relevant: Process Builder and Test Classes Use Case: We have a process that creates a chatter post on user record insert OR profile edit. ...
4
votes
2answers
236 views

'Guest users cannot be record owners' error during deployment of test class to production

I have increased test coverage of a class in QA Sandbox and I am trying to deploy that test class to production. When I run the test class in QA Sandbox, there is no error. But when I am deploying it ...
4
votes
1answer
2k 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 ...
4
votes
1answer
133 views

Why won't Apex IF statement work in Production Unit Testing after working in sandbox?

this is driving me NUTS and any thoughts are MUCH appreciated after looking at this for far too long. Use case: users in certain profiles need to be automatically added/removed from a particular ...
4
votes
2answers
4k views

Test code for the new standard Order object

The last line insert ordPd causes exception: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Price Book Not Set on Order: [] All lines before the ...
4
votes
1answer
675 views

How is the Test Code coverage required for deploying calculated?

Would like to Know- suppose we've sandbox from which we deploy to production. There is already set (A) of classes, some of whose test classes are failing Now we want to deploy Different set(B) of ...
4
votes
3answers
220 views

Unable to load any code to PROD due to Code Coverage of 63% but none of my personal code is below 82 % Test coverage!

I deployed some small triggers to my PROD environment to make life a bit better. However currently noticed that my tests aren't current anymore and I want to update them (as it's stopping me from ...
4
votes
1answer
3k views

Test.setMock not working in Apex test

I am trying to test the server side Controller in Apex test. The controller makes a call out to get account information and returns the response in an Object format to lightning component. The ...
4
votes
2answers
3k views

INACTIVE_OWNER_OR_USER

I'm getting an error INACTIVE_OWNER_OR_USER, operation performed with inactive user, and I have been doing a lot of research and the cause that I have found for this is its attempting to assign a my ...
4
votes
1answer
128 views

Unit test error - You have uncommitted work pending

I get an error in my apex test class You have uncommitted work pending I am aware of the Salesforce limitation in an http callout, we can't perform any DML operations before we send an http callout....
4
votes
1answer
3k views

Process Builder - Failing test classes

I've written a flow in process builder which references an Apex class with @invocable method. I've written a test class for the same and it's passing as well. Now the problem is all the other test ...
4
votes
2answers
71 views

Failing test is showing as passed

In Debug Logs I can see a System.NullPointerException for the unit test that was just run, but on the Apex Test Execution page I see the test as passing. The error is not buried within the log details;...
4
votes
1answer
314 views

What's Wrong With This Apex Code (intent - to delete spam Leads)

I'm still pretty new to programming and especially to SalesForce programming, but I would have expected this suite of trigger, handler class, and test class to: test as expected and show the test ...
4
votes
0answers
260 views

Intermittent Process Builder Flow Error - How to troubleshoot with no info?

Background I'm getting a dreaded flow error for one of our test methods that occurs fairly regularly, but not consistently. I've reviewed the debug logs thoroughly, but can't see any obvious way to ...
4
votes
1answer
434 views

custom setting error when test classes run in parallel

I have a few test classes that fail but only when all the test classes are run in parallel.I'm using a hierarchy custom setting as part of the test code. In order to narrow down the problem I have the ...
4
votes
0answers
855 views

Test method related to Content fails during Deployment, but not when run all test is run

I am facing issues in deploying a change set. This contains one page and class. None of the components are new. There is a slight change in these two components. When I deploy, an unrelated class ...
3
votes
2answers
2k views

Unable to test the result of batch class execution

I am testing a batch file which just changes the field value of records in scope and updates them: global class AbatchClass implements Database.Batchable<sObject>{ global String query; ...
3
votes
2answers
242 views

How is it possible for @TestSetup to effect test result?

While refactoring a test to make it more consistent with the style of our other tests, a colleague came upon something really weird. The original test created the test account in @TestSetup, like so: ...
3
votes
3answers
816 views

Else part in Test Class

how do I cover the else part in this test class public with sharing class RecUtility { public static boolean flag=true; public static boolean runonce(){ if(flag){ flag=false; } else { ...
3
votes
2answers
246 views

What's the uncommitted work on this callout test?

I'm gettin You have uncommitted work pending. Please commit or rollback before calling out.. Exception while Running a Test of the class i will attach. This class is invoked by onTask Trigger (...
3
votes
2answers
11k views

Logged in User in Test class

My apex class extracts all the data of a logged in user for an object. how do I replicate this in my Test class. How do I use System.runAs(User)? The test class is running as me when I say in my code ...
3
votes
1answer
2k views

Query works in Anonymous Window but fails in Test Class

I am new to APEX and ask forgiveness if the answer to my question is obvious, but I can't find a reason for the action that occurs in the Test class versus production and the Developer Console ...
3
votes
1answer
4k views

regarding External entry point

i have one custom field called Unique_Vendor_Id__c on account object (external id checkbox checked) and its auto-number. now in test class when i create account for test data Unique_Vendor_Id__c ...
3
votes
1answer
5k views

How to catch a validation error exception in an apex test class

I have a validation rule that checks if the user tries to enter a Quantity > 100. If so, the validation returns an error. I'm trying to to catch the validation exception, but it seems like the ...
3
votes
1answer
208 views

Test classes pass in validation before deploy, but fail when i run them from “Apex Test Execution”

I have a few apex test class, that pass when i run them while deploying a change set, but when i run them from the setup, in "Apex Test Execution", they fail with the error MIXED_DML_OPERATION (the ...
3
votes
1answer
613 views

attempt to de-reference null object in test class

I'm attempting to write a test method for my constructor and when I get to a method in my non-test class where I'm assigning a value to the object passed I get a "attempt to de-reference null object ...
3
votes
2answers
2k views

Case assignment rule is always executed in the test class

No matter what to do, the case is always assigned by the assignment rule!! You can try the scenario and code which are attached in the post. But, I have tried to execute the code in the developer ...
3
votes
2answers
339 views

Building Dynamic Test Classes that don't break due to Destination Org's - validation rules or Required Field settings

Scenario: I have built a solution for a Customer and I have used Apex for this solution.The deployment went well. But after few months the customer added some validation rules to the Sobject and when ...
3
votes
1answer
1k views

Hierarchy Custom Setting Test Class Issue

I'm using a Hierarchy Custom Setting field in a validation rule but want my trigger to be able to override the validation rule whenever it runs. I have modified my trigger/helper class to set my ...
3
votes
2answers
2k views

Process Builder causing Apex Test class failures - How to handle?

Hoping someone can help with the following issue I am currently experiencing. I have created a new process via the process builder that sets the Contact owner to be the same as the Account Owner on ...

1
2 3 4 5
8