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.

74 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
6
votes
0answers
135 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 ...
5
votes
0answers
335 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
772 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. ...
5
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 ...
4
votes
0answers
180 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
0answers
728 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
313 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
131 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
1answer
311 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 ...
3
votes
0answers
633 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
546 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
27 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
34 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
396 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
101 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
160 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
234 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
0answers
43 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
21 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
30 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
187 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
251 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
72 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
48 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
52 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
78 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
43 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
1k 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
698 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
32 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
35 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
41 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 ...
0
votes
1answer
48 views

Code Coverage 83% in production 75% in sandbox - can't deploy

In production, code coverage is showing 83%. In sandbox, it is showing 75%. I have just 1 apex class and associated test class I am trying to deploy to production, but it fails saying only 30% ...
0
votes
0answers
50 views

APEX Test Class: Round Robin Lead Distribution Model

The original question can be found here. However, as an overview, the code is responsible for assigning Leads to sales representatives with round-robin distribution based on the Queue that is assigned ...
0
votes
0answers
110 views

How to create a correct test for knowledge articles?

I'm creating a package with a simple Apex class that retrieves info about knowledge article (Lighting Knowledge). However, I'm having an issue with a test. When installing the package via installation ...
0
votes
0answers
60 views

Unable to write BestCommentId on FeedItem in test class

I am trying to write a test class to test an Apex class that uses FeedItem object. The Apex class checks if the FeedItem record has a BestCommentId and does some actions. A snippet of the test data ...
0
votes
1answer
216 views

How to solve this deployment errors (Variable does not exist: isReadOnly)?

Trying to deploy package (big one) to a new org but all the tests failed with very weird errors: 1)line -1, column -1: Dependent class is invalid and needs recompilation: Class ClassName : Variable ...
0
votes
0answers
38 views

Test Classes: MIXED_DML_OPERATION

Via Process Builder, Is there anything I can do in my process that could stop this from occurring? Error Message: System.EmailException: SendEmail failed. First exception on row 0; first error: ...
0
votes
2answers
150 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 ...
0
votes
1answer
41 views

Test Method for Case Insert from Trigger

I have a trigger that fires when an Opportunity is Closed Won, has OpportunityLineItems and those OppLineItems relate to a specific Product. The firing of the trigger creates a Case Record based on ...
0
votes
0answers
119 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 ...
0
votes
1answer
367 views

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION

I wrote the validation rule to restrict the custom field picklist value it many test classes is getting failed because of that where and what line i can add into picklist value to cover the test ...
0
votes
0answers
21 views

Can not reproduce behavior within testcase: Duplicate accounts after merge

I'm sorry for the vague description in the header. So here's my problem in detail: I have an automation, that essentially checks a "potential" child record (not master-detail, just lookup) of accounts,...
0
votes
0answers
85 views

Method being called inside a test method returning null reference

I am calling a method to validate passwords in an apex controller which is working by returning either true, false, or null @TestVisible static Boolean validatePassword(){ if (string.valueof(...
0
votes
1answer
32 views

Old unchanged Test Method Fails during deployment of unrelated code

There are similar questions but they hold no answers and are not specific. Error Message / Test Failed during deployment of unrelated code: Test_Method_Test ThisTest System.ListException: List ...
0
votes
1answer
94 views

Test class code coverage error

As of now test class code coverage 85%, but when we are validating the chageset getting 0% code coverage error saying ` STANDARD_PRICE_NOT_DEFINED No standard price defined for this product. ...
0
votes
0answers
139 views

On post request- System.CalloutException: . Please commit or rollback before calling out"?

public with sharing class CalloutHandler { @future (callout=true) public static void createAccount(String id) { Http http = new Http(); HttpRequest req = new HttpRequest(); req.setHeader('...
0
votes
0answers
616 views

Permission Set in Test Class

I have a test class which fails when the Deferred Sharing is on. Because the test data created by the admin user is not seen by another user . and I get insufficient privileges error when i run as new ...
0
votes
0answers
1k views

Apex job is already scheduled for execution

Hi I am getting apex batch already scheduled error while running test class. I don't know where i am going wrong. I am calling batch class from schedule class. Apex Class global class ...