4 votes

ApexTestRunResult's status is set to complete and all tests pass, but the enqueued and completed count do not match

From the ApexTestRunResult docs: MethodsCompleted The total number of methods completed during the test run. This value is updated after each class is run. I'm seeing this discrepancy as well ...
Daniel Ballinger's user avatar
4 votes
Accepted

test class for wrapper class in apex

Your class is not covered because it contains no executable lines of code. There is nothing to cover. It is not necessary to add a constructor for the purpose of simulating coverage. Code coverage is ...
David Reed's user avatar
  • 92.1k
3 votes

Does running all tests in an org impact actual real functionality? Should I not run all tests in production daily?

In theory, running tests at any time should not impact real performance. This is explained in the Isolation of Test Data from Organization Data in Unit Tests documentation. However, some caveats apply....
sfdcfox's user avatar
  • 481k
3 votes
Accepted

What does this do? Throw new MS_Exception

If you remove the MS_Exception class, your code will no longer compile. You would need to, at minimum, change the throw new MS_Exception to a different exception type, such as one of the built-in ...
sfdcfox's user avatar
  • 481k
3 votes

Unable to cover test class for history object

History records aren't created in test contexts, meaning your test will have no records and therefore no coverage. Depending on the test you might be able to get away with using seeAllData in your ...
battery.cord's user avatar
  • 8,767
2 votes
Accepted

how to get Percentage coverage of each ApexClass through SOQL

To query for code coverage, specify an Apex class, test class, or both. The returned JSON or XML object will contain two lists of integers: one for covered and one for uncovered lines. SELECT ...
sanket kumar's user avatar
2 votes
Accepted

Debug Test and Debug All Tests for apex unit tests in VSCodedx

As @sfdcfox says in his comment, I needed to first turn on the replay debugger and then run either Debug All Tests or Debug Test. (To turn on the replay debugger in vscode, command+shif+p/control+...
Bahman.A's user avatar
  • 808
2 votes
Accepted

test classes fail after updating a fields length and its datatype

It's failing because of System.assert(FALSE);. This means it's always going to fail. Usually, you wouldn't hardcode a boolean value when using assert. If you pass something into assert the test only ...
Nicholas Savini's user avatar
2 votes
Accepted

Change Set Deployment - Code coverage failure

Try to update your test class as below and then run test class again and check, let me know any error: @isTest private class PaymentRequestControllerTests { @isTest static void ...
Prathyusha's user avatar
2 votes
Accepted

Test Coverage Issue with Site.getSiteId()

Thanks to @Robert Sösemann, I believe you can apply Facade logic for all Platform methods. You can just change the return type to String, because all Ids are string, but not all strings are ID in apex....
Nagendra Singh's user avatar
2 votes
Accepted

Refactoring Help for main class or test code coverage

You can't override the return value of URL.getSalesforceBaseUrl() in a test class. There's two possible approaches here. One is to factor out the code that calls that method into a separate code unit ...
David Reed's user avatar
  • 92.1k
2 votes
Accepted

DEBUG|Insert failed. First exception on row 0; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, bad value for restricted picklist field

During the insert the record type assignment is missing and the default record type may not have the picklist value that you are trying to insert with, so add the record type assignment- Case newCase =...
Raul's user avatar
  • 18.7k
2 votes
Accepted

Missing ApexTestRunResult Data

They most certainly do get automatically deleted. If they weren't purged periodically they would eventually add up to a significant number of records. Looking in the Dev org I'm currently connected ...
Daniel Ballinger's user avatar
2 votes
Accepted

Test Code coverage for LightningLoginFormController

Great example of how dependency injection can help you out with testing. You have a dependency (Site.login) which you want to express greater control over. Rather than work within its constraints, you ...
Adrian Larson's user avatar
  • 149k
1 vote

Test Code Coverage - Delete DML catch block

You can use the Test.isRunningTest method to check if the code is running in a test context and then throw a custom exception. For example, you can modify your main class code like this: @AuraEnabled ...
Tushar Jadav's user avatar
  • 1,067
1 vote
Accepted

Apex test class not working and fails

The test opportunities you are inserting do not have their required fields populated. Every Opportunity needs a Name, StageName and CloseDate. E.g: new Opportunity(Name = 'Opportunity 1', StageName = '...
fred's user avatar
  • 2,773
1 vote

Issue : "No content to map to Object due to end of input" in test classes

I have the impression that you mock is not matching the endpoint? Thus responding with an empty httpresponse what i mean is : @isTest global class MockHttpResponseGenerator implements HttpCalloutMock {...
Philippe's user avatar
  • 178
1 vote
Accepted

Apex Test for LightningSelfRegisterController

Above dependency injection, you may wish to simply use a real field set. To do so, you need to reorganize the code into slightly smaller chunks. This strategy is a common approach to simplify testing. ...
Adrian Larson's user avatar
  • 149k
1 vote
Accepted

Apex Test for setExperienceId

One solution to this is dependency injection. Define an interface that includes the methods that need to be dependency injected global interface ISite { void setExperienceId(Id experienceId); } ...
cropredy's user avatar
  • 69.9k
1 vote

Problem with Test Class If/Else string is null

You can combine your if statements to produce just one, and this should get you to 100%: for (Service_Console_Fast_Links__c fl : allLinks){ if (this.searchField == null || fl.name....
sfdcfox's user avatar
  • 481k
1 vote
Accepted

APEX Multiple From in Database.getQueryLocator

m is just an alias. You can use it to shorten a query, as demonstrated here (from the documentation): SELECT count() FROM Contact c, c.Account a WHERE a.name = 'MyriadPubs' In your specific case, it ...
sfdcfox's user avatar
  • 481k
1 vote
Accepted

Apex test class for Standard Controller extensions - Test problem

When you're instantiating the StandardController, your passing an Asset record. In the assetonaccount class your constructor method calls controller.getRecord() which will return the record your ...
Dpolehonski's user avatar
1 vote
Accepted

Apex Testing Object Data

That's a horribly inefficient way to use Apex. You can pass in a list of user records directly: @AuraEnabled public static String updateUser(User[] users) { try { update users; } catch(...
sfdcfox's user avatar
  • 481k
1 vote

Trying to Load Data for RecentlyViewed but get error message "Required fields are missing: [OwnerType]"

The RecentlyViewed object doesn’t support the Event, Task, Report, KnowledgeArticle, and Article objects. From the Object Ref doc. I'd question whether the underlying code-under-test ever worked. If ...
cropredy's user avatar
  • 69.9k
1 vote

Cover StandardSetController in Apex Test

Because your Page Controller has an If Statement regarding a listview filter ID, this means you need to render the page without an Id, and with an ID. Now doing this may raise new questions/issues... ...
TheArchitecta's user avatar
1 vote

Cover StandardSetController in Apex Test

First, you need to set the page parameters before the constructor is instantiated Second, you need to determine the expected filterIds so you can use in asserts // Given some mock cases insert cases; ...
cropredy's user avatar
  • 69.9k
1 vote
Accepted

Apex Test Error - Constructor not defined

Firstly: separate the 2 classes, this makes life easier via deployment and source control etc. But to the issue at hand: You are using ApexPages.StandardSetController in your Class, but your test ...
TheArchitecta's user avatar
1 vote
Accepted

Apex Test - Instantiate new Controller

The (datatype name, datatype name, ...) syntax is for defining a function's parameter list. To call it, you simply pass in the parameters. As a simple example: class Counter { Integer value; ...
sfdcfox's user avatar
  • 481k
1 vote

Test running issues

There are two errors at the bottom of your screen. They both state that there is a missing method or incorrect signature. For example, if your TestHelper class has this method: public static void ...
sfdcfox's user avatar
  • 481k
1 vote

How to Schedule Run all apex tests on daily basis

There are many, many ways to automate it. You can subscribe to an app like GearSet to schedule automations, you can set up a CI/CD (Continuous Integration/Continuous Delivery) system to run tests on a ...
sfdcfox's user avatar
  • 481k

Only top scored, non community-wiki answers of a minimum length are eligible