9

Yes, you can, using either of two techniques. Your HttpCalloutMock's respond() method can inspect its inbound HttpRequest, and construct a different response based on which endpoint is being called, the parameters passed, etc. This allows you to write a single class that returns responses for multiple callouts made in sequence in your code under test. ...


6

Nor average, neither sum of percents. If some test methods cover one line of code twice, it only means that this exact line of code is covered. So the actual test coverage is linesCovered / allLines * 100. Example: imagine 1st test class covers one method in your controller (30%), 2nd test class covers 2 methods including the previous mentioned one (50%), ...


6

leads is a List<Lead>, and lists (along with other collections) do not have Ids. The records they contain might, but the list itself will not. Beyond that, SObject records do not have Ids until they are inserted. So you need to insert your Leads first, then iterate over the list of leads to call setCreatedDate static void setup() { List<Lead> ...


6

You can solve that exactely like you solve many other aspects that are hard or impossible to test, like Multicurrency or strange org settings. You let your production code talk to a Facade SystemFacade.isFuture() instead The Facade uses a mock during tests public with sharing class SystemFacade { @TestVisible private static Boolean isFuture = false; // ...


6

Salesforce has a governor limits! In a single apex execution context, you can only do 150 DML operations. Being a beginner to apex I suggest you read through some of the best practices highlighted here Instead of doing DML in a loop, use List to collect all objects and perform one DML instead. @isTest public static void testScenario(){ List<Account&...


4

You have to query back the opportunity in order to see the value of the field. Since the value you are showing on the debug shows the value contained in the variable testOpportunity and not the value of the opportunity stored in memory(which was modified by the trigger). add a line after the update to update the value of the variable with the value stored ...


4

No, it does not. Apex test coverage is calculated as the percentage of lines covered out of total executable lines. The class OpportunityStageNames contains no executable lines of code, so it cannot be covered, and its lines do not contribute to the denominator of the fraction (lines covered)/(total executable lines) across any defined subset of your Apex ...


4

The Test Run Coverage displays the lines of code that were covered during the current test run. The Org Wide Coverage includes all the lines of code that were covered in any previously run unit test. This number may be higher if some unit tests were deleted from the org or no longer cover certain functions. You may want to clear the test coverage from Setup >...


3

In your class updateCheck method is static. you can't invoke static method from an instance of the class in Apex. It should be invoked from a class: instead of updateCaseRecord uC = new updateCaseRecord(); uC.updateCheck(std); should be updateCaseRecord.updateCheck(newCase.Id); you don't need any standard controller, as for VF controller. I recommend ...


3

You need to query the PersonContactId field and use that instead. 001 is always an Account Id, while 003 is always a Contact Id. return accountList; Should be more like: return [SELECT FirstName, LastName, PersonContactId, PersonEmail FROM Account WHERE Id = :accountList]; Then you can: ContactId= accounts[i].PersonContactId,


3

You're overcomplicating this for yourself. Your JSON-deserialization approach writes directly to the object's instance variables and does not invoke the setter methods, which are the only executable lines of code in this class. Also note that the testMethod annotation is deprecated (use @isTest), test methods don't return anything, and it sounds like you ...


3

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 defined as a percentage is executable lives covered, so your wrapper class requires no test class and does not impact your org's coverage.


3

The only way to cover a catch is if you cause your code inside the try to fail. In your case you should get rid of the try/catch because it will never fail (or, let's say you introduce a new validation rule on the Filling it will always fail and you will need to change the trigger). There another good answer that discuss the benefits of catching: When do ...


3

The bottom line these days1 is that if you have a class with the @isTest annotation, everything contained in that class is considered "test code", and does not contribute to your overall test coverage (nor to the 3 million character limit for custom apex code). Before you get any funny ideas, no, you can't use this to get around test requirements. ...


3

As long as you include LeadHelperTest in the change set (or whichever mechanism you're using for deployment), that is enough.


3

You're not supposed to duplicate the logic of the thing being tested in the test itself. The test method is supposed to set up the environment to allow your SUT (system under test) to be run, and then gather results so you can make assertions to verify that the output is what you expect. You only gain coverage for code that is executed as part of a test. ...


3

You just need to allow a way to override the value: @TestVisible static Boolean s_isSandbox = false; static { s_isSandbox = [SELECT Id, isSandbox FROM Organization].isSandbox; } public Boolean isSandbox() { return s_isSandbox; } In your unit test, you can set the variable directly: Utility.s_sandbox = true; // or false // Which allows you to specify if ...


3

You cannot perform DML on ContentDocument (and possibly, ContentDocumentLink too). You only need to insert a test record into ContentVersion and salesforce will automatically create corresponding test records into ContentDocument and ContentDocumentLink objects (which you can query after ContentVersion insert DML). Following code should be good enough in ...


3

So the tests for Managed Packages shouldn't be running for a regular deployment so you should confirm which deployment settings you are using. Managed Package tests will typically never work in your org, since they can't know what settings/validation rules etc you have in place, so make sure you are using the right setting: There are four options when you ...


3

You have at least three problems with your test. First, you're not making any assertions. Second, you didn't test in bulk. Third, you didn't actually test the update logic, even though you have 100% coverage. How do you know the Day__c records are created? You haven't tested it to validate it: System.assertEquals(3, [SELECT COUNT() FROM Day__c]); How do you ...


3

You have a bug that should be causing at least one of your unit test methods to fail, not just to miss code coverage. List<Account> acc=[Select Id,OwnerId from Account Where Id=:c.Id]; cs.AccountId=acc[0].id; No Account will ever have an Id equal to c.Id (you meant c.AccountId). This should result in an exception being thrown when you access the first ...


2

Fortunately, there is an easier way to do this. I often use this while writing apex unit tests. As mentioned in the comment by Kris, you can run specific or all test class methods from a class using the VS code. To be able to see the code highlighted, you need to do enable it from the VS code bottom toolbar. When you have that checked, you will be able to ...


2

Your unit test needs to call the method: @isTest static void testScheduleMe() { Test.startTest(); ContUpdateScheduler.scheduleMe(); Test.stopTest(); } Coincidentally, this will cover the execute method as well.


2

You don't write a unit test for classes like this. Only executable, non-debug, non-test, non-comment lines of code count for code coverage, so this class automatically has 100% code coverage.


2

When you bypass trigger logic, you need to bookend your disablement. Typical flow is as below: @IsTest static void myTest() { // disable trigger // insert data // enable trigger Test.startTest(); // update data Test.stopTest(); // assert against behavior }


2

The flow coverage requirement (default 75%) applies on a per flow basis - based on a test I ran last week Enabled the Deploy Flows as Activated in the target PROD org Deployed a new flow from sandbox + corresponding apex testclass Ran all tests (note that other flows and process builders did not have test classes to cover their logic paths) As the new flow ...


2

Mocks do not replace the need to create and insert appropriate test data to ensure your code executes the logic path you are aiming to test. Here, your unit test code must create and insert a ExtCred__c record that meets the expectations of your code under test. Additionally, you should use Schema methods like getRecordTypeInfosByDeveloperName() to ...


2

These are compilation errors. The system is telling you that it doesn't understand your code. The line numbers tell you were the problematic code is, although sometimes the actual error occurs in another spot. For example, the "Method does not exist..." errors occur on the two lines that contain importData.import_Raw_Data();, but the actual ...


2

There's nothing wrong with your unit test, as far as I can tell. There are many problems wrong with your code. Public with sharing class Case_TriggerHandler extends TriggerHandler { public Case_TriggerHandler(List<Case> newList, Map<Id,case> newMap, List<Case> oldList, Map<Id, Case> oldMap, TriggerOperation type){ super(...


2

You cannot effectively write an integration test against multi-leveled or nested asynchronous Apex, which is what you have here (Schedulable enqueuing Batchable). Test.stopTest() will only force the first layer of asynchronous code to run synchronously. While you may see the other layer (the batchable) execute in logs, it's not really running within your ...


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