Thursday, 3 September 2015

Test classes with @isTest

Use the isTest annotation 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.

  1. Classes and methods defined as isTest can be either private or public. Classes defined as isTest must be top-level classes.
  2. One advantage to creating a separate class for testing is that classes defined with isTest don't count against your organization limit of 3 MB for all Apex code.
  3. You can also add the @isTest annotation to individual methods
  4. Classes defined as isTest can't be interfaces or enums
  5. Methods of a test class can only be called from a running test, that is, a test method or code invoked by a test method, and can't be called by a non-test request.
  6. Test methods can’t be used to test Web service callouts. Instead, use mock callouts
  7. You can’t send email messages from a test method
  8. Methods of a public test class can only be called from a running test, that is, a test method or code invoked by a test method, and can't be called by a non-test request.

@isTest
                    
private class MyTestClass {
   @isTest static void test1() {
      // Implement test code
   }
   @isTest static void test2() {
      // Implement test code
   }
}

IsTest(SeeAllData=true) Annotation

use the isTest(SeeAllData=true) annotation to grant test classes and individual test methods access to all data in the organization,

  1. If a test class is defined with the isTest(SeeAllData=true) annotation, this annotation applies to all its test methods whether the test methods are defined with the @isTest annotation or the testmethod keyword
  2. The isTest(SeeAllData=true) annotation is used to open up data access when applied at the class or method leve

IsTest(OnInstall=true) Annotation

Use the IsTest(OnInstall=true) annotation to specify which Apex tests are executed during package installation. This annotation is used for tests in managed or unmanaged packages


14 comments:

  1. Introduction of cloud servers have created a greatest impact over data interpretation. Also they made a history in cloud computing. Handling data made much easier and more comfortable like never before. Your content tells the same about the emerging technology. Thanks for sharing this information in here.

    Salesforce training in chennai | Salesforce training

    ReplyDelete
  2. Cloud servers are the best in safe guarding one's information thorugh online. Without this dedicated methodology many companies would have not existed at all. The same though has been furnished above. Thanks for sharing this worth while content in here. Keep writing article like this.

    Salesforce Training in Chennai | Salesforce training | Salesforce admin training in chennai

    ReplyDelete
  3. Hi Amit,

    I have a statement and need to confirm whether this statement is correct or not

    "A method annotated @isTest(SeeAllData=true) in a class annotated @isTest(SeeAllData=false) has access to all org data"

    ReplyDelete
  4. New Zealand is inviting dedicated and compassionate nurses to join its healthcare system, set against a backdrop of spectacular scenery and diverse culture. This position is ideal for nurses with valid registration and a commitment to exceptional patient care. Successful candidates will leverage their clinical expertise to deliver comprehensive care and assessment. The role involves collaborating within multidisciplinary teams to implement effective treatment plans tailored to patient needs. Advantages include competitive salaries, robust professional development opportunities, and immersive experiences in a multicultural setting. Relocation support is often available to help ease the transition. Nurses in New Zealand enjoy a balanced lifestyle with excellent work-life integration. This opportunity promises personal growth and professional fulfillment in a breathtaking environment.
    https://www.dynamichealthstaff.com/nurse-vacancy-in-new-zealand

    ReplyDelete