Error: Compile Error: Method is not visible:
We will get this error when we are accessing private methods/variables in test class.
Example:
Apex Class:
public class PrivateMethodDemo {
private void privateMethod() {
}
}
Apex Test Class:
@isTest
private class PrivateMethodDemoTest {
public static testmethod void validate() {
PrivateMethodDemo demo = new PrivateMethodDemo ();
demo.privateMethod();
}
}
When we are saving the above test class,we will get that error.
Solution: Use @TestVisible annotation before private variables/methods of main class.It won't change any functionality of original class.
Modify main class as below
public class PrivateMethodDemo {
@TestVisible private void privateMethod() {
}
}
Now save the test class and run.That's it...
We will get this error when we are accessing private methods/variables in test class.
Example:
Apex Class:
public class PrivateMethodDemo {
private void privateMethod() {
}
}
Apex Test Class:
@isTest
private class PrivateMethodDemoTest {
public static testmethod void validate() {
PrivateMethodDemo demo = new PrivateMethodDemo ();
demo.privateMethod();
}
}
When we are saving the above test class,we will get that error.
Solution: Use @TestVisible annotation before private variables/methods of main class.It won't change any functionality of original class.
Modify main class as below
public class PrivateMethodDemo {
@TestVisible private void privateMethod() {
}
}
Now save the test class and run.That's it...
No comments:
Post a Comment