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 ...
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 ...
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....
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 ...
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 ...
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 ...
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+...
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 ...
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 ...
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....
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 ...
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 =...
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 ...
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 ...
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
...
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 = '...
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 {...
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.
...
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);
}
...
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....
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 ...
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 ...
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(...
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 ...
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...
...
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;
...
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 ...
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;
...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
apextestrunresult × 53apex × 46
code-coverage × 15
unit-test × 10
failing-tests × 7
scheduled-apex × 3
salesforcedx × 2
deployment × 2
salesforcedx-cli × 2
try-catch × 2
trigger × 1
soql × 1
integration × 1
json × 1
callout × 1
picklist × 1
error × 1
sandbox × 1
appexchange × 1
controller-extension × 1
tooling-api × 1
change-set × 1
debugging × 1
email2case × 1
code × 1