Activity Forums Salesforce® Discussions What is the difference between testMethod and @isTest in Salesforce?

  • Adarsh

    Member
    January 16, 2018 at 1:34 pm

    Hello Ankit,

    While creating a Test Method both act same, but @isTest is the enhanced version of 'TestMethod' keyword.

    In case of best practice, we always use @isTest annotation for creating a Test method.

    Hope it helps 🙂

  • Shubham

    Member
    January 16, 2018 at 1:42 pm

    @isTest annotation is used to define the test classes which contains code to test your application and these classes does not count against your over all code coverage.

    Syntax Example:

    @isTest
    private class MyTest {
    // Methods for testing
    }

    testmethod keyword is used to define apex test methods. Also test methods can be defined in any apex class. But we ideally use apex test methods in test classes with @isTest annotation.

    We can also use  @isTest to define apex test methods which is equivalent to the testMethod keyword.

    Syntax Example:

     

    @isTest
    public class myClass {
    static testMethod void myTest() {
    // Add test method logic here
    }
    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos