• #29619
    Forcetalks

    Is it important to include @isTest on Testing Method in Salesforce? Explain?

    Is it important to include @isTest on Testing Method in Salesforce? Explain?

     

    #30114
    Forcetalks

    Hii Avnish,

    Yes, it is important to denote a test class with a separate syntax so that the compiler can understand that its a class where we are going to perform a test. But, instead of using an annotation @isTest, we can also use ‘testmethod’  in a method name.

     

    #34561
    Salesforce | shariq shariq #1
    Forcetalks

    Hi,

    First what is @isTest annotation –

    Use the @isTest annotation to define classes and methods that only contain code used for testing your application. [email protected] annotation on methods is equivalent to the testMethod keyword. The @isTest annotation can take multiple modifiers within parentheses and separated by blanks.

    Classes and methods defined as @isTest can be either private or public. Classes defined as @isTest must be top-level classes.

    @isTest
    private class MyTestClass {

    // Methods for testing
    @isTest static void test1() {
    // Implement test code
    }

    @isTest static void test2() {
    // Implement test code
    }

    }

    Hope this helps.

    #36164
    Salesforce | Parul Parul #2
    Forcetalks

    Adding some points:

    This class is defined using the @isTest annotation. Classes defined as such can only contain test methods. One advantage to creating a separate class for testing as opposed to adding test methods to an existing class is that classes defined with isTest don’t count against your organization limit of 3 MB for all Apex code.
    The advantage to using separate test classes is that they do not count against the limit of the total amount of apex in your org (although this is a soft limit and thus not a overly compelling reason).

    @isTest
    public class TestUtil {

    public static void createTestAccounts() {
    // Create some test accounts
    }

    public static void createTestContacts() {
    // Create some test contacts
    }

    }

     

    Thanks

Viewing 4 posts - 1 through 4 (of 4 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2018 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?