Code Coverage Requirement for Deployment

Before you can deploy your code, at least 75% of Apex code must be covered by tests, and all those tests must pass. In addition, each trigger must have some coverage. Even though code coverage is a requirement for deployment, don’t write tests only to meet this requirement. Make sure to test the common use cases in your app, including positive and negative test cases, and bulk and single-record processing.

Test Method Syntax

@isTeststaticvoidtestName(){// code_block}

Using the isTest annotation instead of the testMethod keyword is more flexible as you can specify parameters in the annotation.

Test classes can be either private or public. If you’re using a test class for unit testing only, declare it as private. Public test classes are typically used for test data factory classes

Here We will Learn how to Write Test class from Zero level and after reading the complete blog you will be the hero of a test class.

Test class best practice

1. Test class must start with @isTest annotation if the class version is more than 25

2. Test environment support @testVisible, @testSetUp as well

3. A unit test is to test a particular piece of code working properly or not.

4. Unit test method takes no argument, commit no data to the database, send no email, flagged with the testMethod keyword.

5. To deploy to production at-least 75% code coverage is required

6. System. debug statement are not counted as a part of apex code limit.

7. Test method and test classes are not counted as a part of code limit

9. We should not focus on the percentage of code coverage, we should make sure that every use case should be covered including positive, negative, bulk and single record.
Single Action -To verify that the single record produces the correct an expected result .
Bulk action -Any apex record trigger, class or extension must be invoked for 1-200 records.

Positive behavior: Test every expected behavior occurs through every expected permutation, i,e user filled out every correct data and not go past the limit.

Negative Testcase: -Not to add future date, Not to specify the negative amount.