function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC Apex DevSFDC Apex Dev 

I tried to write test class for the given apex class... but covered anything... please help me out to write the test class...

APEX CLASS

public class ImplementationTabAccount {
    
    @AuraEnabled
    public static List<Implementation__c> checkingImplementation(Id account) {
        
        List<Opportunity> oppList = new List<Opportunity>();
        oppList = [Select Id, Name from Opportunity where opportunity.AccountId =:account];
        System.debug('Opportunitiessss'+oppList);
        
        Set<Id> oppIds = new Set<Id>();
        if(oppList.size()>0){
            
            for (Opportunity op : oppList) {  
                oppIds.add(op.Id);
            }
        }
        System.debug('oppIds' + oppIds);
        
        List<Implementation__c> impList = new List<Implementation__c>();
        impList = [Select Id,Name,Account_Name__c, Implementation_Stage__c,Opportunity_Name__c FROM Implementation__c where Implementation__c.Opportunity_Name__c=:oppIds];
        System.debug('implist'+impList);
        return impList;
    }
}

TEST CLASS

@isTest
public class ImplementationTabAccountTest {
    static testmethod void test(){
        Account acc= new Account(Name = 'ABC', RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Prospect').getRecordTypeId());
        insert acc;
        
        Opportunity opp = new Opportunity(Name = 'Test', Id = acc.Id);
        insert opp;
        
        Implementation__c impliment = new Implementation__c(Id = opp.Id);
        insert impliment;       
    }    
}
Best Answer chosen by SFDC Apex Dev
Raj VakatiRaj Vakati
Try this class and add all required field for all objects
 
@isTest
public class ImplementationTabAccountTest {
    static testmethod void test(){
        Account acc= new Account(Name = 'ABC', RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Prospect').getRecordTypeId());
        insert acc;
        
       Opportunity opp = new Opportunity();
        opp.name = 'Test';
        opp.AccountId = a.Id;
        opp.StageName = 'Closed Won';
        opp.CloseDate = System.today();
        opp.Type = 'New Customers';
        
        insert opp;
        
        Implementation__c impliment = new Implementation__c(Name ='Test', Opportunity_Name__c = opp.Id);
        insert impliment;       
		
		ImplementationTabAccount.checkingImplementation(acc.Id);
		
    }    
}