Activity Forums Salesforce® Discussions Use of @IsTest versus testMethod and location of test methods in classes

  • Gaurav

    Member
    May 24, 2016 at 10:48 am

    isTest annotation is used to define classes and methods that only contain code used for testing your application. The isTest annotation on methods is equivalent to the testMethod keyword.
    Classes defined with the isTest annotation don't count against your organization limit of 3 MB for all Apex code.
    Classes and methods defined as isTest can be either private or public. Classes defined as isTest must be top-level classes.
    example for private class :-
    @isTest
    private class MyTestClass {
    // Methods for testing
    @isTest static void test1() {
    // Implement test code
    }
    @isTest static void test2() {
    // Implement test code
    }
    }

    example for public class :-
    @isTest
    public class TestUtil {
    public static void createTestAccounts() {
    // Create some test accounts
    }
    public static void createTestContacts() {
    // Create some test contacts
    }
    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos