function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DML2020DML2020 

Apex test classes required when modifying force.com site?

Thinking this may be fundamental:

When a change is made to a .cmp, .js, or .css file by adding aura components, LWC, or adjusting the positioning of them, should an Apex test class be created for those changes as well?

If so, how to go about this? Is this the same as a controller?

Any links to resources to explain this?

Thank you.

Best Answer chosen by DML2020
Malika Pathak 9Malika Pathak 9

Hi DML2020,


1)To determine the decrease in code coverage you have to rerun the test class again and note the overall percentage,
Here is official documentation: https://dreamevent.secure.force.com/articleView?id=sf.code_dev_console_tests_coverage.htm&type=5

2)Mainly test classes name are similar to controllerName but are not inside the controller

For example, In aura component

<aura:component controller="LoginUserUI" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global">
 

Here apex class name is LoginUserUi so its test class name can be LoginUserUI_Test/Test_LoginUserUi,
generally, we append _Test for test class naming(for best practice).

The same goes with Lwc
 

import getContactList from '@salesforce/apex/LoginUserUI.getContactList';
 

To search apex test class you can click:
File > Open and search by controller name, you will be able to find test class if it exists.
To determine the decrease in code coverage you have to rerun the test class again and note the overall percentage,

For test class documentation
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_test.htm

 


If you find this solution is helpful for you please mark best answer

All Answers

AnudeepAnudeep (Salesforce Developers) 
It depends. If your code coverage has decreased after changing the main class, then you have to modify your test class and send that in the same change set.

For lightning components, you will essentially be testing the controller and Jest Test for Lightning Web Components

See example here

Let me know if this helps, if it does, please mark this answer as best so that others facing the same issue will find this information useful. Thank you
DML2020DML2020

Thanks, Anudeep. Though I have a few more:

1. How to determine decrease in code coverage?

2. Where to find the test class to modify, if needed? Would this be contained in the controller file associated with the component?

 

Malika Pathak 9Malika Pathak 9

Hi DML2020,


1)To determine the decrease in code coverage you have to rerun the test class again and note the overall percentage,
Here is official documentation: https://dreamevent.secure.force.com/articleView?id=sf.code_dev_console_tests_coverage.htm&type=5

2)Mainly test classes name are similar to controllerName but are not inside the controller

For example, In aura component

<aura:component controller="LoginUserUI" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global">
 

Here apex class name is LoginUserUi so its test class name can be LoginUserUI_Test/Test_LoginUserUi,
generally, we append _Test for test class naming(for best practice).

The same goes with Lwc
 

import getContactList from '@salesforce/apex/LoginUserUI.getContactList';
 

To search apex test class you can click:
File > Open and search by controller name, you will be able to find test class if it exists.
To determine the decrease in code coverage you have to rerun the test class again and note the overall percentage,

For test class documentation
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_test.htm

 


If you find this solution is helpful for you please mark best answer

This was selected as the best answer