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
Karthik YRCKarthik YRC 

Kindly let me know how to write Test Class for below Class

public class OverrideNewButtonComponentController {
    Public string sObjectType {get; set;}
    Public string keyPrefix {get; set;}
    Public string infoProLabel {get; set;}
    Public string infoProLawonLabel {get; set;}
    
    List<Line_of_Business__c > listInfoProLawson = new List<Line_of_Business__c >();
    public OverrideNewButtonComponentController(String sobjectName, String objPrefix) {
        sObjectType=sobjectName;
        keyPrefix=objPrefix;
    }
    public OverrideNewButtonComponentController(){}

    public PageReference init() {
        String userLawson = String.Valueof([Select id, Lawson_Division__c from User where id = : Userinfo.getUSerId()].Lawson_Division__c);
        if (userLawson != null) {
            listInfoProLawson = [SELECT Id, Name, Lawson_Division__c, Infopro_Division__r.Name from Line_of_Business__c where Lawson_Division__r.Name = :userLawson];
            system.debug('sObjectType==' + sObjectType);
            if (listInfoProLawson.size() == 1 && listInfoProLawson.get(0).Name != null && listInfoProLawson.get(0).Infopro_Division__r.Name != null) {
                String labelVal ;
                if(sObjectType=='Opportunity')
                    labelVal = System.Label.OpportunityNewButtonOverRideLabel;
                else if(sObjectType=='Lead')
                    labelVal= System.Label.LeadNewButtonOverRideLabel;
                labelVal = labelVal.trim();
                List<String> labels = labelVal.split(',');
                System.debug('labels==' + labels);
                infoProLawonLabel = labels.get(0).trim();
                infoProLabel = labels.get(1).trim();
                System.debug(sObjectType+'sObjectTypes---');
Best Answer chosen by Karthik YRC
ManojjenaManojjena
Hi Karthik,

Your full class code is not here .Still start writing test class as below it will give you some code coverage .
 
@isTest
public class TestOverrideNewButtonComponentController{
  private static testMethod void unitTest(){
      OverrideNewButtonComponentController onbc=new OverrideNewButtonComponentController();
	  String str='';
	  String strr='';
     OverrideNewButtonComponentController onbcp=new OverrideNewButtonComponentController(str,strr);
  onbc.init();
  }
}

Lt me know any issue .