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
1k 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 ...
16
votes
4answers
7k 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 ...
9
votes
1answer
304 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
119 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
349 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
543 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 ...
6
votes
1answer
12k 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
4k 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. ...
6
votes
3answers
1k 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
0answers
134 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
1answer
275 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
299 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
334 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
767 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
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
102 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
2answers
963 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 ...
4
votes
1answer
666 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
215 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
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
114 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
2k 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
301 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
176 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
697 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
142 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
586 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
216 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
7k 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
1k 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

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
153 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
417 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
1k 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
260 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
935 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
941 views

Platform Event Testing: Unexpected Exception: Error processing messages

I've been doing a lot of work with Platform events and found it a fantastic way to implement some domain driven design patterns, decouple code, and separate execution contexts. Unfortunately I've been ...
3
votes
1answer
271 views

Testing future Callouts

I am trying to make a future callout sending email name etc from a trigger when a lead is created which is working. The problem is Testing. I am not sure how to go about making this work. I have been ...
3
votes
2answers
465 views

Testing batch apex question

I'm working on a batch job that will change a lead record's Owner when the record was created over 15 minutes ago and is still owned by a particular user. Here's the batch job. This works in ...
3
votes
1answer
198 views

apex test class

Pretty straight forward question: is it possible to run tests without using the Developer Console? I've reached my 5,000 max API Calls and I don't want to wait till' tomorrow to be able to keep ...
3
votes
1answer
2k 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 ...
3
votes
1answer
146 views

Unable to overcome INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY

I'm writing a test class for some trigger functionality and I keep getting the below error when attempting to insert a Case as a User with a specific Profile/Role/Department. ...
3
votes
1answer
288 views

Describe call inconsistent in test class

In the Apex class below (executed in a client org), testA() passes while testB() fails. The failure is an assertion error from the ServiceLayer constructor. /* SF API 33 */ /* PKG version 1.55 */ ...
3
votes
1answer
140 views

sfdx force:apex:test:run all local tests failing

I have a sandbox org (not scratch org). I authenticated it with alias e-devint When run RunLocalTests (hundreds apex test files), it fails quickly with the error below. The error doesn't tell much. ...
3
votes
0answers
297 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 ...