• #21613
    Salesforce | shariq shariq #1

    What is TestVisible Annotation?

    What is the use of TestVisible Annotation?

    #21617
    Salesforce | Shaharyar Shaharyar #8

    @TestVisible Annotation.

    This annotation enables a more permissive access level for running tests only. TestVisible annotation allow test methods to access private or protected members of another class outside the test class. These members include methods, member variables, and inner classes.

    • This example shows how to annotate a private class member variable and private method with TestVisible.

    public class TestVisibleExample {
    @TestVisible private static Integer recordNumber = 1;
    @TestVisible private static void updateRecord(String name) {
    }
    }

    • This is the test class that uses the previous class. It contains the test method that accesses the annotated member variable and method.

    @isTest
    private class TestVisibleExampleTest {
    @isTest static void test1() {
    // Access private variable annotated with TestVisible
    Integer i = TestVisibleExample.recordNumber;
    System.assertEquals(1, i);

    // Access private method annotated with TestVisible
    TestVisibleExample.updateRecord(‘RecordName’);
    // Perform some verification
    }
    }

Viewing 2 posts - 1 through 2 (of 2 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...

Property of Forcetalks.com
Copyright 2017 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?