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
There 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
ReplyDeleteIn the bustling city of Chandigarh, where diverse cultures and languages converge, there is a growing fascination with the Spanish language. Whether you are an avid traveler, a language enthusiast, or someone looking to enhance their career prospects, learning Spanish can open doors to a myriad of opportunities. The Languages Studio is a reputable Spanish language institute in Chandigarh, has emerged as a prominent hub for Spanish language courses. In this article, we will delve into the advantages of learning Spanish in Chandigarh, the unique offerings of The Languages Studio, and why it is the perfect destination for aspiring Spanish speakers.
ReplyDeleteWith numerous of benefits such as appetite reduction and improvement of mental health, the best weight loss supplement brings a noticeable difference by blocking for the fat storage. It is an inspirational supplement that does Slimming Gummies Erfahrungennot create any health issues or risk at all. The remedy does not require any prescription or a special effort at all. It helps to shape up your whole body in a glorified way.No user is going to experience the side-effect of using Slimming Gummies. Even in the most temporary stomach pain and discomfort or not felt on choosing the supplement. It has chromium picolinate garcinia Cambodia and other natural extracts that approved and are clinically tested.Dietary supplement is absolutely safe and is mare with hundred percent natural extracts. You should consume the recommended dose of 2 gummies per day and observe changes in your body within a span of 90 days. The effectiveness of weight loss remains natural but maybe subjective in nature.Dietary supplement is absolutely safe and is mare with hundred percent natural extracts. https://www.5min.at/202304642723/slimming-gummies-erfahrungen-test-neueste-bewertungen-2023/
ReplyDeleteEmblem Technologies is a leading technology consulting firm in the USA, providing innovative solutions to businesses. With a strong focus on digital transformation and cutting-edge technologies, Emblem Technologies offers expertise in areas such as cloud computing, artificial intelligence, cybersecurity, data analytics, and software development. Their team of skilled consultants assists clients in leveraging technology to enhance efficiency, streamline operations, and drive growth. Emblem Technologies is known for its strategic approach, deep industry knowledge, and commitment to delivering tailored solutions that meet the unique needs of each client
ReplyDeleteDiscover the enchanting world of Layesha Lashes. Unveil captivating eyelash extensions and accessories to enhance your natural beauty.
ReplyDeleteGermany plays a pivotal role in global transportation as a strategic hub in Europe. With world-class airports, well-developed ports, and a sophisticated rail network, it offers seamless connectivity for goods and passengers. Its logistical expertise, combined with efficient customs procedures, makes it an ideal gateway for international trade and travel
ReplyDeleteDermatology is the medical specialty that deals with the diagnosis and treatment of skin, scalp, and finger problems. It's a medical and surgical specialty that combines the two.
ReplyDeleteAt DNA Driveways, we are experts at installing a range of different driveways throughout Warrington. Your driveway helps to protect your property from the weight of any vehicles, foot traffic and from the weather. It is also important in helping your home to look attractive!
ReplyDeletehi
ReplyDeleteCorporate scandals, such as financial fraud, environmental violations, or labor abuses, present significant challenges for journalists. Reporting on these issues requires access to confidential information, protection of whistleblowers, and the ability to navigate legal threats from powerful corporations. Despite the risks, investigative journalism plays a crucial role in exposing wrongdoing and holding companies accountable. Effective reporting on corporate scandals can lead to legal consequences for perpetrators and drive industry reforms.News
ReplyDeleteThe global nature of news today means that events occurring in one part of the world can have far-reaching implications elsewhere. International news coverage has become more accessible, but it also faces challenges related to cultural sensitivity and bias. News organizations must navigate these complexities to provide accurate and nuanced reporting on global issues. Additionally, the rise of citizen journalism and user-generated content from around the world contributes to a more interconnected news environment, though it also raises questions about verification and credibility.News
ReplyDeleteThe line between virtual and real-world racing is becoming increasingly blurred. Many professional drivers use sim racing as a training tool to practice on virtual versions of real-world tracks. During the COVID-19 pandemic, when many real-world Car Sports racing events were canceled, professional drivers turned to sim racing to stay competitive and entertain fans.
ReplyDelete