function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
akhil Vakhil V 

@TestVisible annotation(deployment error)

Hi i have a class and need a code coverage for that i wrote a test class bt it is not passing the private method in test class,so i kept @testvisible annotation to private method then it was passed,when i have done the deployment i got a error about @testvisible annoation ?can any one say how to rectify and deploy my code to production.?
Thanks in Advance,
Akhil
Sumitkumar_ShingaviSumitkumar_Shingavi
What is the error you got? Can you post the message?

1. Is your prod up with Sprint'15 release as @testVisible is released in Spring'15?
2. Are you following code in below form:

Class with Private members:
public class TestVisibleExample {
    // Private member variable
    @TestVisible private static Integer recordNumber = 1;

    // Private method
    @TestVisible private static void updateRecord(String name) {
        // Do something
    }
}

Test Class for unit testing private members/methods:
@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
    }
}

Thanks,
Sumit
akhil Vakhil V
Thanks for Reply sumit,
my prod org is not up to spring15 release and the above thing i have followed to acces private members,i got the error message as private methods are not accessible during deployment
Thanks,
Akhil
ManojjenaManojjena
Hi Akhil,
If you have added @testVisibele in your class private method ,So you have the right to edit your class .
So simpley edit your class update the versionn to latest version like 33 then save and deploy it will help.

 
Sumitkumar_ShingaviSumitkumar_Shingavi
If your org. is not setup for API 33 (Spring'15) then you need to wait until Salesforce releases it to your prod. Also, once prod gets Spring'15 release; you can update API version of class by editing it and push it to prod though changeset. -Sumit
ManojjenaManojjena
Hi,
@testvisible is released before winter 15 .So you can use chage your version to 30 ,it will work .