• #21613
    Salesforce | shariq shariq #120

    What is TestVisible Annotation?

    What is the use of TestVisible Annotation?

    Salesforce | Shaharyar Shaharyar #433

    @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.

    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
    // Perform some verification

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

Please to reply to this topic.


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


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


Forgot your details?