How To Write Test Class | Basics | Salesforce
TEST CLASS BASICS
In this episode, we will talk about all the salesforce basics of an apex Test class.
Before starting anything we have to first understand why we have to write salesforce test class.
So let's get started kid...
When You Will Write Test Classes ?
* If you want to validate whether the application what we have created is working as expected.
There are two ways of testing an application.
1. Using Salesforce User Interface
2. Testing bulk functionality (Upto 200 records can be passed through your code)
So before you deploy your code (to production)or package (managed) to the Force.com AppExchange the following conditions should be satisfied.
1) At least 75% of your Apex code must be covered by the unit test.
2) All the test cases must be covered successfully.
NOTE : When you deploy any code into production all the Test Methods will be executed and the test classes are not part of Apex code coverage.
Points to be noticed :
- Every Trigger must have a test case.
- All apex classes and triggers should compile successfully.
What are the Factors that Need to be Tested in Apex Programming :
1. Single Action : This is to test a single record, produces the correct expected result.
2. Bulk Actions : Any Apex code, whether a trigger, a class or an extension, may be invoked for 1 to 200 records. You must test not only the single record case but the bulk cases as well.
3. Positive Behaviour : Test to verify that the expected behaviour occurs through every expected permutation, that is the user filled out everything correctly and did not go past the limits.
4. Negative Behaviour : There are likely to your applications, such as not being able to add a future date, not being able to specify a negative amount & So on.
5. Restricted User : Whether a user with restricted access used in your code.
Apex Unit Test :
A unit test is the class methods that verify whether a particular piece of code is working properly or not.
Unit test method takes no arguments and commits no data to the database, will not send any emails.
Test Method Keyword :
- When you want to create a test method should be prefixed with the keyword testmethod.
- All the test methods are static.
For Example :
===========================================
public class myClass
{
static testMethod void myTest()
{
//Add test method logic using system.assert(), system.assertEquals()
//And system.assertNotEquals() here
}
}
===========================================
NOTE : testmethods cannot be defined in the Apex Trigger.
@isTest Annotation :
- If you define any method as @isTest then the method is the test method.
- If any class is defined with annotation @isTest then that class is defined as test class.
Example 1 :
===========================================
@isTest
private class myclass
{
static testMethod void myTest()
{
//code_block
}
}
===========================================
This is the same test class as in the previous example but it defines that test method with the isTest annotation instead.
Example 2 :
===========================================
@isTest
private class myclass
{
@isTest static void myTest()
{
//code_block
}
}
===========================================
NOTE: Class defined with the isTest annotation don't count against your organization limit of 3MB for all apex code.
Example 3 :
===========================================
@isTest
private class MyTestClass
{
//Methods for testing
@isTest static void test1()
{
//Implement test code
}
@isTest static void test2()
{
//Implement test code
}
}
==========================================
- Test classes must be defined as @isTest with access specifies as public/private.
- ByDefault access level is private.
- Methods of the test class can be called only from the running method.
- A test method cannot be invoked in the non-test method.
So these are the basic fundamental things you must know before writing any apex test classes in salesforce ☁️⚡️
I hope you now it's quite easy for you to write salesforce test classes because now you know when and why exactly we write salesforce apex test classes.
In the next episodes, we will discuss and learn how to write test classes for all the type of your code wherever it is necessary. In a very easy way because when your purpose of writing code is clear you are always good to go.
WOHOOO !! YOU HAVE JUST COMPLETED SALESFORCE TEST CLASS BASICS EPISODE
If you like this salesforcekid learning platform please let me know in the Comment section...Also, Share with your salesforce folks wish you
Happy learning ☁️⚡️ (Learn. Help. Share.)
If you like this salesforcekid learning platform please let me know in the Comment section...Also, Share with your salesforce folks wish you
Happy learning ☁️⚡️ (Learn. Help. Share.)
How To Write Test Class | Basics | Salesforce
Reviewed by
on
Rating:

Hi, I was hoping you could give insight on how @AuraEnabled classes are to be tested such as when you are passing the recordid back to the component. I am trying to do an assertion when I start test but the list is returning null.
ReplyDeleteCould you please share more details about it ?
DeleteNice post. I was checking constantly this blog and I’m impressed! Extremely useful info specially the last part I care for such information a lot. I was seeking this certain info for a long time. Thank you and good luck.write for us
ReplyDeleteThis is one of the new casinos gaming sites that intends to please its high roller clients. real casino online gambling
ReplyDeleteFake health organizations. Scammers pose as health authorities like the World Health Organization (WHO) and U.S. make money from home
ReplyDeleteKoçak Vize Vize Hizmetleri Vize işlemleri Elçiliğe Gitmeden Vize Alma Online Vize Başvurusu İşlemleri Vize Danışmanlık Firması olarak hizmetinizdeyiz Almanya vizesi
ReplyDelete
ReplyDeleteReally impressive post. I read it whole and am going to share it with my social circles. I enjoyed your article and am planning to rewrite it on my own blog . how to get a united nations passport
De Oral-B CrossAction opzetborstels maken het gemakkelijk om je tanden goed te poetsen. De opzetborstel heeft borstelharen die ontworpen zijn om effectief tot 100% meer plak te verwijderen dan een gewone handmatige borstel. Hij is voorzien van CrissCross borstelharen die niet alleen diep tussen de tanden reiken om gen weg te vegen, maar ook in tegengestelde richting staan om tand voor tand te reinigen. De borstel bevat ook power tip borstelharen die extra lang zijn en doordringen tot moeilijk bereikbare plaatsen, zoals de achterkant van de mond, waardoor u elke keer een effectieve en grondige reiniging krijgt. Voor wie op zoek is naar een effectieve en toch zachte poetservaring bieden de Oral-B CrossAction opzetborstels een geweldige oplossing. Cross action opzetborstels
ReplyDeleteDe Google Florida Core Update heeft de wereld van SEO grondig door elkaar geschud en de manier waarop websites worden gerangschikt en ontdekt drastisch veranderd. De update zou een poging zijn geweest om de gebruikerservaring te verbeteren, door betere rankings van inhoudsbronnen van hogere kwaliteit en het belonen van actuele en nauwkeurig weergegeven informatie. Veel website-eigenaren hebben veranderingen gezien; ze hebben soms het gevoel dat hun zichtbaarheid of ranking sterk is aangetast. Tegelijkertijd wordt gehoopt dat deze update gebruikers die voorheen met irrelevante zoekresultaten werden geconfronteerd, veel meer mogelijkheden biedt. In de toekomst moeten webmasters ernaar streven aantrekkelijke inhoud te creëren, ondersteund door accurate informatie om de vruchten te plukken van de Google Florida Core; zich concentreren op relevantie boven al het andere zou de sleutel tot succes kunnen zijn. Google core Update Florida November 2020
ReplyDeleteThere are even times when I feel so down but now I will feel better right after checking your blogs. You have made me feel so good about myself all the time and please know that I do appreciate everything that you have in your blog top gun leather jacket. I absolutely loved each little bit of it and I additionally have you bookmarked to see new things on your site.
ReplyDeleteWe provide Spanish language course Patiala that are implemented by trained and experienced professionals. We provide video-based flashcards to review the material, no textbooks are required. We held conversation-based Spanish programs. We provide both options of Learn Spanish language Patiala or live classes with us. We too give an opportunity of a free trial with our well-experienced professionals.
ReplyDeletewant simplest take a look at the ideal Scorecard to understand which standards the code in front of them needs to meet to align with the rest of the software. Better Breathing Sport The Scorecards can be made the usage. Chillwell AC of data from custom resources and Query Language (CQL). CQL additionally allows the querying of records in. order that authors and reviewers alike can fast locate solutions for your team’s documentation to any questions they have which might be applicable to the review handy. https://www.outlookindia.com/outlook-spotlight/better-breathing-sport-device-reviews-2023-does-it-work-latest-warning-info-detailed-price-news-277628
ReplyDeletehttps://www.outlookindia.com/outlook-spotlight/chillwell-portable-ac-2023-does-it-work-or-latest-scam-uses-benefits-risk-price-news-279631
ReplyDeleteLanguage Studio is a renowned institute that offers comprehensive Spanish language courses Patiala. Their courses are designed to cater to learners of all levels, from beginners to advanced speakers. With experienced teachers and a well-structured curriculum, Language Studio provides an immersive learning experience that helps students develop their Spanish language skills quickly and effectively. Whether you want to learn Spanish for personal or professional reasons, Language Studio has a course that suits your needs.
thanks pobg
ReplyDeleteConsumers internet marketing you ought to related pursuit ahead of creation. It is very easy to jot down top-notch write-up in that possition. Herbal remedies for flu
ReplyDeleteRapidly this kind of fantastic web site will surely unquestionably often be well-known amongst many creating any website people, for your meticulous articles along with testimonies. cheap iptv
ReplyDeleteThat'sthe cause marketing that you simply appropriate research prior to creating. It's also feasible to put in writing enhanced publishing with this particular. roof leakage solutions in india
ReplyDeleteI prefer the particular distribute. It is actually outstanding to learn someone verbalize from the cardiovascular system and in addition top quality using this important material could be simply experienced. https://healthfitmine.com/
ReplyDeleteThis is exactly each an awesome content and articles document really quite quite beloved reading. This isn't on daily basis i feature capability to work out a huge concern. whipped cream chargers cracker
ReplyDelete