You need to sign in to do that
Don't have an account?
divya1234
here is the quick background:- i wrote a validation rule to restrict the picklist value on user object but there is losts of test claases are getting failed. i choose teh approach to create a helper class to create user test data then i can call. i tried to write the test class not sure it will work please help me with the good approach . how can i can mmy helper class into my test class
global class TestClassHelper
{
public User CreateUser()
{
//Get a profile id from the data base to assign to our user in this case make them a sys admin
Profile p = [select id from profile where name='System Administrator'];
//Create a new sys admin user and do an insert
User u = new User(alias = 'standt', email='noEmail@testorg.com',
emailencodingkey='UTF-8', lastname='Testo', languagelocalekey='en_US', localesidkey='en_US', profileid = p.Id,
timezonesidkey='America/Los_Angeles', username='MrTestUser@testorg.com',Resource_Type__c='Employee');
User u1 = [Select u.Profile.Name, u.ProfileId, u.Name, u.Id From User u where u.Profile.Name = 'System Administrator' limit 1];
return u;
}
public User CreateUser(string userType)
{
//Get a profil id from the data base to assign to our user in this case make them a sys admin
Profile p = [select id from profile where name=:userType];
//Create a new sys admin user and do an insert
User ur = new User(alias = 'standt', email='noEmail@testorg.com',
emailencodingkey='UTF-8', lastname='Testo', languagelocalekey='en_US', localesidkey='en_US', profileid = p.Id,
timezonesidkey='America/Los_Angeles', username='MrTestUser@testorg.com',Resource_Type__c='Employee');
return ur;
}
}
Looking for helper test class to create test user data
here is the quick background:- i wrote a validation rule to restrict the picklist value on user object but there is losts of test claases are getting failed. i choose teh approach to create a helper class to create user test data then i can call. i tried to write the test class not sure it will work please help me with the good approach . how can i can mmy helper class into my test class
global class TestClassHelper
{
public User CreateUser()
{
//Get a profile id from the data base to assign to our user in this case make them a sys admin
Profile p = [select id from profile where name='System Administrator'];
//Create a new sys admin user and do an insert
User u = new User(alias = 'standt', email='noEmail@testorg.com',
emailencodingkey='UTF-8', lastname='Testo', languagelocalekey='en_US', localesidkey='en_US', profileid = p.Id,
timezonesidkey='America/Los_Angeles', username='MrTestUser@testorg.com',Resource_Type__c='Employee');
User u1 = [Select u.Profile.Name, u.ProfileId, u.Name, u.Id From User u where u.Profile.Name = 'System Administrator' limit 1];
return u;
}
public User CreateUser(string userType)
{
//Get a profil id from the data base to assign to our user in this case make them a sys admin
Profile p = [select id from profile where name=:userType];
//Create a new sys admin user and do an insert
User ur = new User(alias = 'standt', email='noEmail@testorg.com',
emailencodingkey='UTF-8', lastname='Testo', languagelocalekey='en_US', localesidkey='en_US', profileid = p.Id,
timezonesidkey='America/Los_Angeles', username='MrTestUser@testorg.com',Resource_Type__c='Employee');
return ur;
}
}
1) http://amitsalesforce.blogspot.com/2017/01/test-utility-classes-testdatafactory.html
Update your test helper like below
Let us know if this will help you
public static testMethod void testAccountPhoneFax(){
TestHelper.createCustomSettings();
setupData();
TestClassHelper.CreateUser();
System.runAs(u)
{
System.debug('Current User: ' + UserInfo.getUserName());
System.debug('Current Profile: ' + UserInfo.getProfileId());
}
public User CreateUser(string userType) method in my test class