{"id":1556,"date":"2026-09-07T17:00:00","date_gmt":"2026-09-07T11:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/apex-test-class-basics-code-coverage\/"},"modified":"2026-09-07T17:00:00","modified_gmt":"2026-09-07T11:30:00","slug":"apex-test-class-basics-code-coverage","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/apex-test-class-basics-code-coverage\/","title":{"rendered":"Apex Test Class Basics and the 75% Code Coverage Rule"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">An Apex Test Class is a special class that runs your code with sample data and checks that the result is correct. Salesforce will not let you deploy Apex to production without tests, so every developer writes them from day one. Good tests also catch bugs before your users do.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this post, you will learn what a test class looks like, how test data works, what the 75% code coverage rule really means, and how to write your first passing test. It builds on <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-classes-and-objects-constructors\/\">Apex classes and objects<\/a>, <a href=\"https:\/\/swapnilzambare.com\/blog\/dml-operations-in-apex\/\">DML operations in Apex<\/a> and <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-exception-handling-custom-exceptions\/\">Apex exception handling<\/a>. This is the first post of Level 5: Testing and Debugging.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is an Apex Test Class?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">An Apex Test Class is a class marked with the @isTest annotation. Its methods create test data, call your real code and then check the results with asserts. Data created inside a test is never saved for real, because Salesforce rolls it back when the test ends.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a driving test. The examiner does not trust that you can drive because you own a car. Instead, they sit next to you, give you real situations and check each move. A test class is the examiner for your code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why an Apex Test Class Matters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Tests are not only a deployment rule. Here is why every Apex Test Class matters at Bright Path Tutors.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, production deployments need at least 75% code coverage across your Apex code.<\/li>\n\n<li>Also, every trigger needs some test coverage before you can deploy it.<\/li>\n\n<li>Next, tests catch bugs when someone changes old code months later.<\/li>\n\n<li>Salesforce runs your tests before every major release to find platform issues early.<\/li>\n\n<li>Finally, a good test explains how the code should behave, like living documentation.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">So tests protect your users, your team and your future self.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How an Apex Test Class Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">An Apex Test Class follows a clear flow. First, you mark the class and its methods with @isTest. Next, each test method creates its own test data, such as a few Course__c records. Then the method calls the code you want to test. After that, asserts compare the actual result with the expected result. Finally, Salesforce rolls back all test data and records which lines of code ran, which gives you code coverage.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-test-class-basics-code-coverage-diagram-1-1024x640.png\" alt=\"Apex Test Class diagram showing @isTest, test data, call code, assert, rollback and coverage steps\" class=\"wp-image-1554\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-test-class-basics-code-coverage-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-test-class-basics-code-coverage-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-test-class-basics-code-coverage-diagram-1-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-test-class-basics-code-coverage-diagram-1-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-test-class-basics-code-coverage-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">How a test class checks code and measures coverage.<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">The @isTest Annotation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You put @isTest on the class and on each test method. Test classes are usually private, because nothing else needs to call them. Code inside an @isTest class does not count toward your org&#8217;s Apex code size limit.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Test Methods<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A test method is static, returns void and takes no parameters. Give it a clear name that says what it checks, such as appliesTenPercentDiscount.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Test Data<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">By default, tests cannot see the records in your org. So each test creates the data it needs. This keeps tests independent, and they behave the same in every sandbox and in production.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Asserts<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">An assert checks one fact, such as &#8220;the fee is now 4,500&#8221;. If the fact is false, the test fails with your message. We cover all the assert methods in a later post.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Code Coverage<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Code coverage is the percentage of your code lines that ran during tests. It shows what was executed, not whether the result was right. That is why asserts matter as much as coverage.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Deployment Rules for Apex Tests<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The table below lists the rules Salesforce checks when you deploy Apex to production.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Rule<\/th><th>What it means<\/th><\/tr><\/thead><tbody><tr><td>75% overall coverage<\/td><td>At least 75% of all Apex lines must run in tests<\/td><\/tr><tr><td>Trigger coverage<\/td><td>Every trigger needs some coverage<\/td><\/tr><tr><td>All tests pass<\/td><td>Any failing test blocks the deployment<\/td><\/tr><tr><td>Test code excluded<\/td><td>Test classes do not count in coverage totals<\/td><\/tr><tr><td>Sandboxes<\/td><td>No coverage rule, but test there anyway<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Normal Class vs Apex Test Class<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The table below compares a normal class with an Apex Test Class.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Normal Apex class<\/th><th>Apex test class<\/th><\/tr><\/thead><tbody><tr><td>Annotation<\/td><td>None needed<\/td><td>@isTest<\/td><\/tr><tr><td>Saves data<\/td><td>Yes<\/td><td>No, rolled back<\/td><\/tr><tr><td>Sees org records<\/td><td>Yes<\/td><td>No, by default<\/td><\/tr><tr><td>Counts toward code size limit<\/td><td>Yes<\/td><td>No<\/td><\/tr><tr><td>Runs when<\/td><td>Users or automation call it<\/td><td>You run tests or deploy<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When to use which is simple. Write normal classes for business logic, and write at least one test class for each of them.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-test-class-basics-code-coverage-diagram-2-1024x640.png\" alt=\"Apex Test Class diagram comparing a normal Apex class and an Apex test class\" class=\"wp-image-1555\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-test-class-basics-code-coverage-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-test-class-basics-code-coverage-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-test-class-basics-code-coverage-diagram-2-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-test-class-basics-code-coverage-diagram-2-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-test-class-basics-code-coverage-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Normal class vs Apex test class.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">A Real Apex Test Class Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s write an Apex Test Class for a small fee service at Bright Path Tutors. The service gives a discount on course fees, but only between 0% and 50%.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: The Code to Test<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class CourseFeeService {\n\n    public static void applyDiscount(List&lt;Course__c&gt; courses, Decimal percent) {\n        if (percent == null || percent &lt; 0 || percent &gt; 50) {\n            throw new IllegalArgumentException('Discount must be between 0 and 50');\n        }\n        for (Course__c c : courses) {\n            if (c.Fee__c != null) {\n                c.Fee__c = c.Fee__c - (c.Fee__c * percent \/ 100);\n            }\n        }\n        update courses;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The method checks the percent first. Then it lowers each fee and saves all courses with one update. So there are two paths to test: a valid discount and an invalid one.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Write the Test Class<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>@isTest\nprivate class CourseFeeServiceTest {\n\n    @isTest\n    static void appliesTenPercentDiscount() {\n        Course__c c = new Course__c(Name = 'Apex Basics', Fee__c = 5000);\n        insert c;\n\n        CourseFeeService.applyDiscount(new List&lt;Course__c&gt;{ c }, 10);\n\n        Course__c saved = [SELECT Fee__c FROM Course__c WHERE Id = :c.Id];\n        Assert.areEqual(4500, saved.Fee__c, 'Fee should drop by 10%');\n    }\n\n    @isTest\n    static void rejectsTooLargeDiscount() {\n        Course__c c = new Course__c(Name = 'SOQL Basics', Fee__c = 3000);\n        insert c;\n        try {\n            CourseFeeService.applyDiscount(new List&lt;Course__c&gt;{ c }, 80);\n            Assert.fail('Expected an IllegalArgumentException');\n        } catch (IllegalArgumentException e) {\n            Assert.isTrue(e.getMessage().contains('between 0 and 50'));\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first method creates one course, applies a 10% discount, queries the course again and checks the new fee. The second method tries an 80% discount. If no exception is thrown, Assert.fail stops the test. Otherwise, the catch block checks the error message.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Run the Tests<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In the Developer Console, click Test &gt; New Run, select CourseFeeServiceTest, and click Run. You can also open Setup &gt; Apex Test Execution, or run tests from VS Code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Read the Results<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a simplified view of what the results show.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CourseFeeServiceTest.appliesTenPercentDiscount   Pass\nCourseFeeServiceTest.rejectsTooLargeDiscount     Pass\nCode coverage: CourseFeeService   100%<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Both tests pass, and every line of CourseFeeService ran. More importantly, the asserts prove the code gives the right answer, not just that it ran.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Coverage Is Not the Goal<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Many teams chase 75% and stop there. However, a test without asserts can reach 100% coverage and still prove nothing. So aim for tests that check real behaviour: valid input, invalid input and bulk data. Coverage then follows naturally.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with an Apex Test Class<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Writing tests with no asserts, just to raise coverage.<\/li>\n\n<li>Using SeeAllData=true, which makes tests depend on org data.<\/li>\n\n<li>Testing only the happy path and never the error path.<\/li>\n\n<li>Hard-coding record Ids that do not exist in other orgs.<\/li>\n\n<li>Putting many unrelated checks in one huge test method.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for an Apex Test Class<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create all test data inside the test, so tests run anywhere.<\/li>\n\n<li>Add at least one meaningful assert to every test method.<\/li>\n\n<li>Test valid input, invalid input and bulk input of 200 records.<\/li>\n\n<li>Name test methods after the behaviour they check.<\/li>\n\n<li>Keep one test class per class, with a clear name such as CourseFeeServiceTest.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Add a third test method that applies a 0% discount and checks that the fee does not change. Hint: copy the first method and change the percent and the expected value.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Most Asked Interview Questions on Apex Test Class<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Almost every Salesforce developer interview starts with testing questions. Here are the 21 questions asked most about the Apex Test Class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic Questions on Apex Test Class<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1: What is a test class in Apex?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is a class marked @isTest that creates test data, runs your code and checks the results with asserts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2: What is the minimum code coverage for production?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">75% of all Apex code in the org, and every trigger needs some coverage. All tests must also pass.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3: How do you declare a test method?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use @isTest on a static void method with no parameters.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4: Is test data saved to the database?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. Salesforce rolls back all data created in a test when the test ends.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5: Can a test see existing org records?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Not by default. Some setup data, such as users and profiles, is still visible.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6: Does test code count toward the Apex code size limit?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. Classes and methods marked @isTest do not count.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7: Where can you run Apex tests?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the Developer Console, Setup &gt; Apex Test Execution, VS Code or the Salesforce CLI.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Code and Scenario Questions on Apex Test Class<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8: What does SeeAllData=true do?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It lets the test read real org data. Avoid it, because tests then fail when data changes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9: How do you test that code throws an exception?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Call the code in a try block, call Assert.fail after it, and check the exception in the catch block.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10: Why should tests use 200 records?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Triggers receive up to 200 records at a time, so bulk tests prove the code stays inside governor limits.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11: Can a test class have a public access modifier?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes, but private is common. A public @isTest class is often used for shared test data helpers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12: How do you test code that runs as a specific user?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use System.runAs with a test user to check sharing and permissions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13: What happens if a test has no asserts?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It can still pass and add coverage, but it proves nothing about the result.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14: How do you check the coverage of one class?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run its tests, then view the coverage in the Developer Console, VS Code or Setup &gt; Apex Classes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced Questions on Apex Test Class<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15: Is 75% coverage enough?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is the minimum. Many teams aim for 85% or more, with meaningful asserts on every path.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16: Why do tests that pass in a sandbox fail in production?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Often they rely on org data, hard-coded Ids or settings that differ between orgs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17: Do tests count toward governor limits?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Test code runs with the same limits as normal Apex in each transaction.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18: What is Test.isRunningTest?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It returns true when code runs inside a test. Use it sparingly, because it hides real behaviour.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q19: Can you test private methods?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Not directly. Mark them @TestVisible, or test them through the public methods that call them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q20: Do Salesforce releases run your tests?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Salesforce runs customer tests before major releases to find platform regressions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q21: What makes a good test class?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Its own test data, clear method names, positive, negative and bulk tests, and meaningful asserts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_testing.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Testing Apex (Apex Developer Guide)<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_code_coverage_best_pract.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Code Coverage Best Practices (Apex Developer Guide)<\/a><\/li>\n\n<li><a href=\"https:\/\/trailhead.salesforce.com\/content\/learn\/modules\/apex_testing\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Testing (Trailhead)<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>An Apex Test Class is marked @isTest and checks your code with test data.<\/li>\n\n<li>Test data is rolled back and cannot see org records by default.<\/li>\n\n<li>Production needs 75% overall coverage, trigger coverage and passing tests.<\/li>\n\n<li>Coverage shows what ran, while asserts prove it worked.<\/li>\n\n<li>Test valid, invalid and bulk input in every class.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Creating test data in every method gets repetitive. Next, read our guide to the <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-test-data-factory-testsetup\/\">Apex Test Data Factory and @TestSetup<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An Apex Test Class is a special class that runs your code with sample data and checks that the result is correct. Salesforce will&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1553,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[8,96],"tags":[98,111,26,91,7,97],"swapz_series":[],"class_list":["post-1556","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-salesforce","category-salesforce-developer","tag-apex","tag-apex-testing","tag-intermediate","tag-interview-questions","tag-salesforce","tag-salesforce-developer"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Apex Test Class Basics and the 75% Coverage Rule<\/title>\n<meta name=\"description\" content=\"Apex Test Class basics explained simply: @isTest, test methods, test data, the 75% code coverage rule, deployment rules and 21 interview Q&amp;A.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/swapnilzambare.com\/blog\/apex-test-class-basics-code-coverage\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apex Test Class Basics and the 75% Coverage Rule\" \/>\n<meta property=\"og:description\" content=\"Apex Test Class basics explained simply: @isTest, test methods, test data, the 75% code coverage rule, deployment rules and 21 interview Q&amp;A.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/apex-test-class-basics-code-coverage\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-07T11:30:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-test-class-basics-code-coverage-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Swapnil Zambare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Swapnil Zambare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-test-class-basics-code-coverage\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-test-class-basics-code-coverage\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/922ac0131aaa7088c78c2cb1700e0c9a\"},\"headline\":\"Apex Test Class Basics and the 75% Code Coverage Rule\",\"datePublished\":\"2026-09-07T11:30:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-test-class-basics-code-coverage\\\/\"},\"wordCount\":1736,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-test-class-basics-code-coverage\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-test-class-basics-code-coverage-featured.png\",\"keywords\":[\"Apex\",\"Apex Testing\",\"Intermediate\",\"Interview Questions\",\"Salesforce\",\"Salesforce Developer\"],\"articleSection\":[\"Salesforce\",\"Salesforce Developer\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-test-class-basics-code-coverage\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-test-class-basics-code-coverage\\\/\",\"name\":\"Apex Test Class Basics and the 75% Coverage Rule\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-test-class-basics-code-coverage\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-test-class-basics-code-coverage\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-test-class-basics-code-coverage-featured.png\",\"datePublished\":\"2026-09-07T11:30:00+00:00\",\"description\":\"Apex Test Class basics explained simply: @isTest, test methods, test data, the 75% code coverage rule, deployment rules and 21 interview Q&A.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-test-class-basics-code-coverage\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-test-class-basics-code-coverage\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-test-class-basics-code-coverage\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-test-class-basics-code-coverage-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-test-class-basics-code-coverage-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Apex Test Class featured image: title card with an Apex code example\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-test-class-basics-code-coverage\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Apex Test Class Basics and the 75% Code Coverage Rule\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"name\":\"Swapnil Zambare - Blog\",\"description\":\"Salesforce &amp; Tech Guides\",\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\",\"name\":\"Swapnil Zambare - Blog\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"width\":512,\"height\":512,\"caption\":\"Swapnil Zambare - Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/theSwapnilZambare\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/922ac0131aaa7088c78c2cb1700e0c9a\",\"name\":\"Swapnil Zambare\",\"sameAs\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\"],\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/author\\\/swapnil-zambare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Apex Test Class Basics and the 75% Coverage Rule","description":"Apex Test Class basics explained simply: @isTest, test methods, test data, the 75% code coverage rule, deployment rules and 21 interview Q&A.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/swapnilzambare.com\/blog\/apex-test-class-basics-code-coverage\/","og_locale":"en_US","og_type":"article","og_title":"Apex Test Class Basics and the 75% Coverage Rule","og_description":"Apex Test Class basics explained simply: @isTest, test methods, test data, the 75% code coverage rule, deployment rules and 21 interview Q&A.","og_url":"https:\/\/swapnilzambare.com\/blog\/apex-test-class-basics-code-coverage\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-09-07T11:30:00+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-test-class-basics-code-coverage-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/apex-test-class-basics-code-coverage\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-test-class-basics-code-coverage\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/922ac0131aaa7088c78c2cb1700e0c9a"},"headline":"Apex Test Class Basics and the 75% Code Coverage Rule","datePublished":"2026-09-07T11:30:00+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-test-class-basics-code-coverage\/"},"wordCount":1736,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-test-class-basics-code-coverage\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-test-class-basics-code-coverage-featured.png","keywords":["Apex","Apex Testing","Intermediate","Interview Questions","Salesforce","Salesforce Developer"],"articleSection":["Salesforce","Salesforce Developer"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/apex-test-class-basics-code-coverage\/","url":"https:\/\/swapnilzambare.com\/blog\/apex-test-class-basics-code-coverage\/","name":"Apex Test Class Basics and the 75% Coverage Rule","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-test-class-basics-code-coverage\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-test-class-basics-code-coverage\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-test-class-basics-code-coverage-featured.png","datePublished":"2026-09-07T11:30:00+00:00","description":"Apex Test Class basics explained simply: @isTest, test methods, test data, the 75% code coverage rule, deployment rules and 21 interview Q&A.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-test-class-basics-code-coverage\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/apex-test-class-basics-code-coverage\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/apex-test-class-basics-code-coverage\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-test-class-basics-code-coverage-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-test-class-basics-code-coverage-featured.png","width":2400,"height":1260,"caption":"Apex Test Class featured image: title card with an Apex code example"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/apex-test-class-basics-code-coverage\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Apex Test Class Basics and the 75% Code Coverage Rule"}]},{"@type":"WebSite","@id":"https:\/\/swapnilzambare.com\/blog\/#website","url":"https:\/\/swapnilzambare.com\/blog\/","name":"Swapnil Zambare - Blog","description":"Salesforce &amp; Tech Guides","publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/swapnilzambare.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/swapnilzambare.com\/blog\/#organization","name":"Swapnil Zambare - Blog","url":"https:\/\/swapnilzambare.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","width":512,"height":512,"caption":"Swapnil Zambare - Blog"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/in\/theSwapnilZambare"]},{"@type":"Person","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/922ac0131aaa7088c78c2cb1700e0c9a","name":"Swapnil Zambare","sameAs":["https:\/\/swapnilzambare.com\/blog"],"url":"https:\/\/swapnilzambare.com\/blog\/author\/swapnil-zambare\/"}]}},"_links":{"self":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1556","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/comments?post=1556"}],"version-history":[{"count":0,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1556\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/1553"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=1556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=1556"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=1556"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=1556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}