Activity › Forums › Salesforce® Discussions › What is TestVisible Annotation in Salesforce?
Tagged: Salesforce Annotation, Salesforce Methods, Test Class in Salesforce, TestVisible Annotation, Winter 15
-
What is TestVisible Annotation in Salesforce?
Posted by shariq on August 11, 2017 at 1:46 PMWhat is the use of TestVisible Annotation?
Avnish Yadav replied 7 years, 7 months ago 3 Members · 2 Replies -
2 Replies
-
@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
}
} - [adinserter block='9']
-
Adding more @testvisible is released before winter 15 .So you can use in your version to 30 or more
Thanks.
Log In to reply.