+ Start a Discussion
DeveloperDeveloper 

How to cover test code coverage lightning help me

public with Sharing Class test 
{
    @AuraEnabled
    public static List<Id> testmethod(String testmethod1)
    {
        List<Id> testmethodIds = new List<Id>();
        for(ILine_Item__c iLineItemReg : [SELECT Id, class__c
                                                                FROM ILine_Item__c
                                                                WHERE Inspection_Line_Item__c = :testmethod1])
        {
         testmethodIds.add(iLineItemReg.class__c);
        }
        return testmethodIds;
    }
}

 
Best Answer chosen by Developer
Raj VakatiRaj Vakati
@isTest
private class testTestCls {

    static TestMethod void myUnitTest()
	{
		Profile profile1 = [Select Id from Profile where name = 'System Administrator'];
       System.debug('What is the profile id ' + profile1);
       UserRole portalRole = [Select Id From UserRole Where PortalType = 'None' Limit 1];
       date tDate = date.today();
       date uDate = Date.today().addDays(30);
        
         User u = new User(
            UserRoleId = portalRole.Id,
            ProfileId = profile1.Id,
            Username = 'testtermsconditions1234423@demooo.com',
            Alias = 'batman',
            Email='testtermsconditions1234423@demooo.com',
            EmailEncodingKey='UTF-8',
            Firstname='Bruce',
            Lastname='Wayne',
            LanguageLocaleKey='en_US',
            LocaleSidKey='en_US',
            TimeZoneSidKey='America/Chicago');
            insert u;
          
        
       
        
        System.runas(u) {
			
		
		
		Test.startTest();
			ILine_Item__c  l = new ILine_Item__c ();
			l.Name ='Test';
			l.Inspection_Line_Item__c='Test';
			l.Class__c ='Test';
			insert l ;
			test.testmethod('Test');
																	   
			
			
		Test.stopTest();
		}
    }
}

 

All Answers

Raj VakatiRaj Vakati
@isTest
private class testTestCls {

    static TestMethod void myUnitTest()
	{
		Profile profile1 = [Select Id from Profile where name = 'System Administrator'];
       System.debug('What is the profile id ' + profile1);
       UserRole portalRole = [Select Id From UserRole Where PortalType = 'None' Limit 1];
       date tDate = date.today();
       date uDate = Date.today().addDays(30);
        
         User u = new User(
            UserRoleId = portalRole.Id,
            ProfileId = profile1.Id,
            Username = 'testtermsconditions1234423@demooo.com',
            Alias = 'batman',
            Email='testtermsconditions1234423@demooo.com',
            EmailEncodingKey='UTF-8',
            Firstname='Bruce',
            Lastname='Wayne',
            LanguageLocaleKey='en_US',
            LocaleSidKey='en_US',
            TimeZoneSidKey='America/Chicago');
            insert u;
          
        
       
        
        System.runas(u) {
			
		
		
		Test.startTest();
			ILine_Item__c  l = new ILine_Item__c ();
			l.Name ='Test';
			l.Inspection_Line_Item__c='Test';
			l.Class__c ='Test';
			insert l ;
			test.testmethod('Test');
																	   
			
			
		Test.stopTest();
		}
    }
}

 
This was selected as the best answer
Raj VakatiRaj Vakati
@isTest
private class testTestCls {

    static TestMethod void myUnitTest()
	{
		Profile profile1 = [Select Id from Profile where name = 'System Administrator'];
       System.debug('What is the profile id ' + profile1);
       UserRole portalRole = [Select Id From UserRole Where PortalType = 'None' Limit 1];
       date tDate = date.today();
       date uDate = Date.today().addDays(30);
        
         User u = new User(
            UserRoleId = portalRole.Id,
            ProfileId = profile1.Id,
            Username = 'testtermsconditions1234423@demooo.com',
            Alias = 'batman',
            Email='testtermsconditions1234423@demooo.com',
            EmailEncodingKey='UTF-8',
            Firstname='Bruce',
            Lastname='Wayne',
            LanguageLocaleKey='en_US',
            LocaleSidKey='en_US',
            TimeZoneSidKey='America/Chicago');
            insert u;
          
        
       
        
        System.runas(u) {
			
		
		
		System.Test.startTest();
			ILine_Item__c  l = new ILine_Item__c ();
			l.Name ='Test';
			l.Inspection_Line_Item__c='Test';
			l.Class__c ='Test';
			insert l ;
			test.testmethod('Test');
																	   
			
			
		System.Test.stopTest();
		}
    }
}