Activity Forums Salesforce® Discussions What is TestVisible Annotation in Salesforce?

  • Shaharyar

    August 12, 2017 at 3:10 am

    @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

  • Avnish Yadav

    September 30, 2018 at 3:26 am

    Adding more @testvisible is released before winter 15 .So you can use in your version to 30 or more


Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos