test class

Test Class in Salesforce - All You Need To Know

Below are some of the key points to note about the Test Class in Salesforce:

  • Test Classes and test methods verify whether a particular piece of code is working properly or not. 
  • If that piece of code fails, then developers/testers can accurately locate the test class having the faulty bug.
  • Test strategies and test classes are not considered pieces of Apex code limit
  • Each trigger you are attempting to convey ought to have in any event 1% inclusion, yet yes generally speaking inclusion of your creation organization subsequent to getting your code sent ought to be 75%, in any case, Salesforce won't let you send your code. 
  • Salesforce.com emphatically suggests utilizing a test-driven advancement measure which happens simultaneously as code improvement.
  • At the point when I was learning Salesforce unit testing, I understand that it is hard to comprehend where to begin reading.
  • Along these lines, I summed up the unit testing for Salesforce fledglings to comprehend the fundamental parts of unit testing

dont miss out iconDon't forget to check out: Tips and Tricks For Test Class In Salesforce

Single Action: Test to confirm that a solitary record delivers the right, anticipated outcome. 

Mass Action: Test the single record case, yet the mass cases also 

Positive Behavior: Verify that normal conduct happens through each normal change 

Negative Behavior: Verify that the mistake messages are effectively created 

Confined User: Test whether a client with limited admittance to the sObjects utilized in your code sees the normal conduct 

Test Class can be characterized by @isTest comment. Prior to the Winter 21' discharge, we had just private test classes, yet on Winter 21' discharge, Salesforce has allowed us to compose open test classes also. Salesforce has delivered open test classes to uncover regular techniques for information creation. 

  • The key strategies to use in your unit tests are the system.assert() techniques. There are three sorts of system.assert() techniques. 
  1. System.assert(condition) 
  2. System.assertEquals(x,y) 
  3. System.assertNotEquals(x,y) 

Benefits of Apex Unit Test

  • Ensuring that your apex classes and triggers work as expected.
  • Having a suite of regression tests that can be re-run every time classes and triggers are updated to ensure that future updates you make to your app don’t break existing functionality.
  • Meeting the code coverage requirements for deploying apex to production to distribute apex to customers via packages.
  • High-quality apps delivered to the production org, which makes production users more productive.
  • We need to use attest techniques for the security survey as well as a best practice.

Structure of the Test Class

private classTest_class 
    open static testMethodvoid test_name(){ 

dont miss out iconCheck out another amazing blog by Pooja here: 10 Reasons to Switch On Salesforce Lightning

Structure of Open Test Class for Test Information Creation

open class TestUtil { 
    open static void createTestAccounts() { 
        /Create some test accounts 
    open static void createTestContacts() { 
        /Create some test contacts 


Popular Salesforce Blogs