You need to sign in to do that
Don't have an account?
SkyBlue2007
How to test some private member variables in a class !
Hi all,
I tried to test my custom controller, and I got a error message "Variable is not visible" when I saved my test class.
Here's a controller.
public class SampleController { private User user {get; set;} private String pritest {get; set;} public String pubtest {get; set;} public LoginController () { String userid = UserInfo.getUserId(); user = [select testfield__c from User where id = :userid]; pritest = 'abc';
pubtest = 'xyz'; } public PageReference login() { ・・・・・・・ } }
Here's a test class.
@isTest private class SampleControllerTests { public static testMethod void testMyController() { Profile p = [select id from profile where name='Standard User']; User u = new User(alias = 'standt', email='standarduser@testorg.com', emailencodingkey='UTF-8',lastname='Testing',languagelocalekey='en_US', localesidkey='en_US', profileid = p.Id,timezonesidkey='America/Los_Angeles', username='standarduser@testorg.com'); System.runAs(u) { PageReference pageRef = Page.SamplePage; Test.setCurrentPage(pageRef); SampleController controller = new SampleController(); String pritest = controller.pritest; String pubtest = controller.pubtest; System.assertEquals('abc', pritest); System.assertEquals('xyz', pubtest); } } }
Please let me know how to test some private member variables in a class.
Thanks,
SkyBlue2007
You can not assert private number varibles in test class. If you want to be assure of tehm them use system.assert in your controller itself.
All Answers
You can not assert private number varibles in test class. If you want to be assure of tehm them use system.assert in your controller itself.
Hi Shashikant,
Thank you for your prompt reply.
I understand wha you said.
Thanks,
SkyBlue2007
Your welcome, it was my pleasure to solve your problem..
@TestVisible private Integer myPrivateInteger;