public with sharing class Sample
{
public string selectedValue {get; set;}
public List<SelectOption> industry {get; set;}
public void getIndustry()
{
Schema.DescribeFieldResult industryDescription = Account.Industry.getDescribe();
industry = new List<SelectOption>();
for (Schema.Picklistentry pl : industryDescription.getPicklistValues())
{
industry.add(new SelectOption(pl.getValue(),pl.getLabel()));
}
}
public void checkValue()
{
System.debug('Selected Industry Type - ' + selectedValue);
}
}
public with sharing class Sample {
public List<AccountWrapper> accountWrapperList {get; set;}
public Sample (){
if(accountWrapperList == null) {
accountWrapperList = new List<AccountWrapper>();
for(Account a: [SELECT Id, Name From Account Limit 10]) {
accountWrapperList.add(new AccountWrapper(a));
}
}
}
public class AccountWrapper {
public Account acc {get; set;}
public Boolean isSelected{get; set;}
public AccountWrapper(Account a) {
acc = a;
isSelected = false;
}
}
}
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 annotation enables a more permissive access level for running tests only. This annotation doesn’t change the visibility of members if accessed by non-test classes.
With this annotation, you don’t have to change the access modifiers of your methods and member variables to public if you want to access them in a test method. For example, if a private member variable isn’t supposed to be exposed to external classes but it should be accessible by a test method, you can add the TestVisible annotation to the variable definition.
This example shows how to annotate a private class member variable and private method with TestVisible and how to access it in test class.
Sample Class:
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:
@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
}
}
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject