You need to sign in to do that
Don't have an account?
Soundar Rajan Ponpandi
How to cover a test class for this simple controller
Dears,
I would like to cover a test class for this simple code , But i am facing a following Error.
public class GD_TradeLicenseRunningBanner {
@AuraEnabled
public static String fetchUser(){ User oUser = [select id,Name,TimeZoneSidKey,contactId,Username,Alias,Country,Email,FirstName,LastName,IsActive,IsPortalEnabled, Contact.accountId FROM User Where id =: userinfo.getuserId() ]; account acc = [select id,name,GD_General_Info__c from account where id=: oUser.contact.accountId Limit 1];
return acc.GD_General_Info__c;
}
}
@Test CLass
Thanks in advance.
Soundar.
I would like to cover a test class for this simple code , But i am facing a following Error.
Error: Compile Error: Static method cannot be referenced from a non static context: String GD_TradeLicenseRunningBanner.fetchUser() at line 39 column 15
public class GD_TradeLicenseRunningBanner {
@AuraEnabled
public static String fetchUser(){ User oUser = [select id,Name,TimeZoneSidKey,contactId,Username,Alias,Country,Email,FirstName,LastName,IsActive,IsPortalEnabled, Contact.accountId FROM User Where id =: userinfo.getuserId() ]; account acc = [select id,name,GD_General_Info__c from account where id=: oUser.contact.accountId Limit 1];
return acc.GD_General_Info__c;
}
}
@Test CLass
@isTest Public class GD_TradeLicenseRunningBannerTest{ @testSetup static void testSetupMethod(){ system.debug('Running Into the test class'); profile pr = [SELECT Id,Name FROM Profile WHERE Name = 'GD PP Sales Rep']; User usr = new User(Alias = GD_TestDataFactory.generateUniqueText(), Email='test@test.com', EmailEncodingKey='UTF-8', LastName='Test', LanguageLocaleKey='en_US', LocaleSidKey='en_US', ProfileId = pr.Id, TimeZoneSidKey='America/Los_Angeles', UserName=GD_TestDataFactory.generateRandomUserName()); Insert usr; account acc = new account(); acc.name='test'; insert acc; contact con = new contact(firstname='testName', lastName='testName', accountId = acc.id); insert con; Opportunity Opp = new Opportunity(Name = 'Test Opp', CloseDate = Date.today()); System.Test.startTest(); GD_TradeLicenseRunningBanner trade = new GD_TradeLicenseRunningBanner(); trade.fetchUser(); System.Test.stopTest(); } }
Thanks in advance.
Soundar.
Replace
with
Please mark the answer if it helps.
All Answers
Replace
with
Please mark the answer if it helps.
Thanks for your quick response!
Now it's not showing any error ,but still class is not covering.
But still the class is showing 0% code coverage.
Regards,
Soundar.
But still code coverage is 0%