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.

88 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
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
0answers
63 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
844 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
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
0answers
420 views

Test passes when run alone; fails when run with other methods in the same class

I've got a test that passes when run by itself, but fails when run alongside another method in the same class. No changes were made between test runs, and I have made sure to select Disable Parallel ...
3
votes
2answers
156 views

Why is my task trigger test failing

I have a task trigger which updates two custom fields on the Account object : Last_Call_Date and Last_Meeting_Date. I have tried logging a task in sandbox and it updates the fields correctly. However,...
3
votes
0answers
739 views

Reference field returning NULL in Test class only

We are facing a very strange issue when writing proper unit test using asserts. We have two objects which have logical link with a field. So, we wrote a batch class to relate those two objects using ...
3
votes
1answer
626 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 ...
2
votes
0answers
51 views

Apex test class enable product scheduling

Test Class Error: System.DmlException: Upsert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: unknown (scheduling not enabled on product): [...
2
votes
0answers
76 views

In a test class example of a Post Install script, sending an email and scheduling a class that performs an API callout

Scenario: In my example, as a part of the PostInstall (class implements InstallHandler) script I will be performing two actions; - sending an email to the installing User for the express purpose of ...
2
votes
2answers
93 views

Apex Test Class Failure: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]

I am at a loss for this one and could really use some help on this. I have a vf page and apex extension that is used with a site. Everything works when I test this via the UI but for some reason I am ...
2
votes
0answers
706 views

How to Avoid exceeding CPU Time Limit in Test Classes?

I am currently updating test classes in our org and it seems that most of them are exceeding the CPU Time Limit. They are using the @testSetup to create a lot of test data and it seems that these DML ...
2
votes
0answers
120 views

Why Field Accessibility Check is broken in a Managed Package?

my code has a centralised class which is responsible for all DML operations. This class before inserting / updating / deleting a record is checking: 1, if the object is accessible for the current ...
2
votes
1answer
231 views

Testing Batch Class that triggers Chatter Post

I have a batch class that needs a test class. In creating the test records, the insertion of a necessary object record triggers a Chatter Post via another trigger. That chatter post references a ...
2
votes
0answers
260 views

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY on Communities Change Username Page Test

I created a visualforce page for Communities users to update their username and email. In real life the page works fine, logging in as a Community user I can update my username and email. However, I ...
1
vote
2answers
117 views

Test Class for the Apex Class with try Catch block fails

I am trying to write a test class for the Apex Class with try - catch block and this is my first time coding test classes. The Apex Class is like below which has trycatch public class ...
1
vote
0answers
35 views

'uncommitted work pending' callout exception thrown in *tests only*

I am converting a lead in the Execute method of a batch class, then making 2 callouts with those results in the Finish() method. It works gloriously and throws no errors. However, in the test ...
1
vote
0answers
54 views

Test Class failing with Too many SOQL queries: 101

My test class is public static testMethod void loanSetDelegatedApprovers() { list<User> userList = new list<User>(); list<Approval_Delegate__c> adList = new list<...
1
vote
0answers
23 views

Batch fails to deploy

I have a batch that I uploaded into Production successfully on July 20th and then a change to that batch on July 27th, both with no issues. I needed to make another change to that batch today, so I ...
1
vote
0answers
57 views

Unaltered Test passes in Sandbox AND Production, but fails during unrelated deployment validation

I am trying to deploy a few classes. I've got a Sandbox that I literally created this morning off of Production. Nothing is different between the two except the 3 classes I'm deploying. How can it ...
1
vote
0answers
181 views

Force calculation of Cross Object formula to be used in test class

The basic gist of my issue is that I have a batch apex class that uses cross object formulas in some IF statements (Something like Contact.Account.FirstName). The problem is that when I create the ...
1
vote
0answers
257 views

Apex test classes fail on HTTPResponse

I have some test classes that run decently until they hit something like HTTResponse res = h.send(req); Where I then get 'System.UnexpectedException: Script-thrown exception'. I make a few ...
1
vote
0answers
478 views

How can I view my test classes debug logs of an ant deploy

I have about 20 classes that I deploy to production via ant. Some of my test classes fail. I want to view the debug logs but I cannot find the way to look at the logs of my ant deployment. Any help ...
1
vote
0answers
86 views

APEX Plugin failing test but working otherwise

I've got a trigger that helps copy some stuff over when a lead is cloned trough a visual workflow. Even though it works properly when testing it in the flow, the plugin fails when trying to unit test ...
1
vote
0answers
50 views

Test method failure - expecting a DML error but not getting one

I have a test method that is failing because it is expecting an error, but isn't getting one. Here's the test method: static testMethod void assignToSelf_DmlError() { setup(); Test.startTest(...
1
vote
2answers
56 views

Apex Test issues creating a quote - page error missing or inactive pricing type/pricebook

I am trying to update some older test code to remove seeallData=true. I am getting a page error testing a quote controller extension that creates a new quote. System.AssertException: Assertion ...
1
vote
2answers
80 views

Assert Failing - cant update apexclass

We have a class that was previously deployed into production. I have made a small change to the class, simply modifying a string that contains the campaign name so we can use the class on a new ...
1
vote
1answer
45 views

Unable to make coverage for the below class

I have written a test class for the apex class.I am not able to cover the following portion .can you help me out. thanks in advance Apex Class: //Generated by wsdl2apex public class ...
1
vote
0answers
2k views

How to test an input file?

I have this controller i want to test: public class SubirCV { public ContentVersion contentToUpload {get;set;} public Id memberId{get; set;} public Blob fileContent {get;set;} public SubirCV(...
1
vote
0answers
2k views

Insert contact statement in test class is causing 0% code coverage

I've written a simple trigger to prevent duplication of a lead based on existing leads and contacts. My test has 90% code coverage based on the tests that I've written to prevent lead duplication. ...
1
vote
0answers
758 views

Can you ignore test failures when installing an unmanaged package?

I want to install an unmanaged package in our production environment but I know that a couple of tests will fail due to settings specific to our org. I would like to be able to install it and then ...
0
votes
0answers
24 views

MIXED_DML_OPERATION Error in Test Case with S2XUserMap

Before starting, I know about DML operations and the order they should be performed in for test cases. Please do not comment on that. These test cases succeed and have been succeeding in partial and ...
0
votes
0answers
11 views

Test succeeds in packaging org, but fails during packaging

We are trying to avoid using globalDescribe as that can eat a ton of time in larger orgs. So we are trying Type.forName to get SObjectType and their describes without hitting the costly global ...
0
votes
0answers
41 views

Confounded by Test Class Failing in Production but Passing in all Identical Sandboxes

I finally have to ask some other folks about this one. There's a test class from an (awful) unmanaged package in our org, and it has been there for a year and never been a problem, but suddenly it is ...
0
votes
1answer
26 views

Testing chained continuations

Im wondering if anyone has figured out a way to test chained continuations? I followed the documentation for how to essentially make two asynchronous callouts in a synchronous pattern. I can test the ...
0
votes
0answers
30 views

RecordType using Test.loadData in Testclass for account object

I am trying to export data in csv from one sandbox and trying to load the same data into Test class using loadData method. Currently , I am struggling in creating RecordType within Test class For ...
0
votes
0answers
39 views

Mixed DML causing test classes to fail to to Process builder

I have a Test class which was working fine but after a new process builder was created on user object to update a custom field created on user object, it started failing. In my test class code I am ...
0
votes
0answers
60 views

I don't know how to get 100% code coverage of this code

This code is used to prevent a case from being closed when it still has open tasks. When the user tries to close a case with an open task an error message pops up. Instead of using a Status from the "...
0
votes
1answer
30 views

SOQL injection issue on source scanner report

I am getting SOQL injection vulnerability on source scanner report. Please check one of the issue below. I tried string.escapeSingleQuotes() on query string. It is helping with removing this issue in ...
0
votes
0answers
24 views

Getting INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY when mocking an Object using Stub API

I am mocking a routing rule object by using the JSON list below that has an ID of type Routing_Rule__c. The Test is about creating some rules and setting some flags that would cause the lead object to ...
0
votes
1answer
26 views

Workflow Task Error When Trying to Deactivate a User from a SandboxPostCopy Apex Test

I'm trying to deactivate a user in an apex test. But am getting an error that the user (that I just created in the test) in being used by workflow tasks. The class implements SandboxPostCopy and is to ...
0
votes
1answer
83 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() { .....
0
votes
0answers
53 views

AuthProvider is visible from Test Method

@isTest public with sharing class AuthProviderCtrlTest { @isTest public static void getAuthProviderTest() { List<AuthProvider> providers = AuthProviderCtrl.getProviders() ...
0
votes
0answers
83 views

Deployment of apex code to production

I am trying to get rid of some old apex code in a Salesforce org. There are few test classes on production org which are broken because 1) they were written a few years back with old API version or 2) ...
0
votes
1answer
116 views

Too many SOQL queries error encountered when running the class in Sandbox but not in Production

I have experienced a bunch of test classes fail to pass in a Sandbox, but execute fine in Production. Has anyone some good tips on what look out specifically? I think the code itself is not ...
0
votes
1answer
51 views

Why are field updates inside an Apex trigger not showing up in an Apex test?

I have a very strange issue with some Apex tests for a trigger. The tests each check a different type of field update; when one field is changed, the trigger is supposed to change another field. On a ...