You need to sign in to do that
Don't have an account?
mikka
How to write test coverage to meet conditions for UserInfo language?
Hi guys, Just want to ask how can I create a test coverage with this certain piece of code: if (UserInfo.getLanguage() == 'en_US') { //implementation goes here... } else if (UserInfo.getLanguage() == 'zh_TW') { //implementation goes here... } How can I write test coverage both for English and Chinese language? Is there a method like setLanguage which is good only for executing test coverages? Currently my test coverage is lower than 75% because it cannot cover the other language since it uses the default language set in the portal. Please help!!! Many many thanks for those who will reply... Mikka ^_^
In unit tests, you can create a new user programmatically and then run code as that user - would that work in your scenario?
Hi Bob_buzzard,
Thanks for your reply. I was also eyeing for that but do you have an idea on how to connect the Account object to User object to define the LanguageLocaleKey of the certain client/user I will be creating? Currently, I have this pseudocode:
Account accountSuccessTest = new Account( FirstName='AcME',
LastName='GX', RecordTypeId = PersonAccountTypeId,
Client_Id__c = '!@#$%^&*()',
Client_ID__pc='abcde12345',
First_Name_Chinese__c= ' ',
Last_Name_Chinese__c = ' '
);
Insert accountSuccessTest;
Then, I want this new account to be associated to the new user that I will be creating having a LanguageLocaleKey of 'zh_TW'. Such a time that I will call the method I am testing to pass these set of fields:
formatNameWithPolicyId(accountSuccessTest.FirstName,
accountSuccessTest.LastName,
policySuccessTest.policy_number__c,
accountSuccessTest.First_Name_Chinese__c,
accountSuccessTest.Last_Name_Chinese__c);
So that when I run the test coverage, the languagelocalekey that can be detected from this client is Chinese.
If these sounds more confusing, I will gladly reply to elaborate this further.
Again many thanks!!!
Mikka ^_^