+ Start a Discussion
chiranjib routchiranjib rout 

suggest unit test class for this trigger

hii friends please suggest me  test class for this  below. i have also written one test class but showing error
Trigger RevenueWithoutST on Revenue__c (before insert,Before Update) {

    List<SCSCHAMPS__Appointment__c> appList;
    List<Revenue__c> revlist = new List<Revenue__c>();
    string eCode;
    date salaryDate;
    string category;
    string type;
    Integer month;
    Integer year;
    
    for(Revenue__c rev:Trigger.new)
    {
        eCode=rev.ECode__c;
        salaryDate=rev.Salary_Processed_Month__c;
        month=rev.Salary_Processed_Month__c.month();
        year=rev.Salary_Processed_Month__c.year();
        category=rev.InvoiceCategory__c;
        type=rev.Invoice_Type__c;      
        if(eCode!=null)
        {
           appList =[select AvvasECode__c,Name_of_the_Candidate__c,Client_Name__c,Date_of_Onboarding__c,Last_Working_Date__c,Location__c from SCSCHAMPS__Appointment__c where AvvasECode__c=: ecode] ;
            
            for(SCSCHAMPS__Appointment__c app : appList)
            {
               rev.Talent_Name__c= app.Name_of_the_Candidate__c;
               rev.Client_Name__c=app.Client_Name__c;
               rev.DOJ__c=app.Date_of_Onboarding__c;
               rev.Last_Working_Date__c=app.Last_Working_Date__c;
               rev.Location__c=app.Location__c;
            }
        }

        if((eCode!=null) && (category=='individual') &&(salaryDate!=NULL) )
        {
            List<Invoice__c> InvList;                                                                              
            InvList=[select id,Name,Emp_Code__c,Invoice_Category__c,Sub_Total__c,Invoice_Date__c from Invoice__c where Emp_Code__c=: ecode
                    AND CALENDAR_MONTH(Invoice_Date__c)=:month AND CALENDAR_YEAR(Invoice_Date__c)=:year ];
              System.debug('+++invoice'+InvList);
              
              
                FOR(Invoice__c inc : InvList)
                {
                  
                  rev.Revenue_Without_ST__c=inc.Sub_Total__c;
                }

        }

        else if(eCode!=null && category=='consolidated')
        {

            List<Invoice_Line_Item__c> ILineList;
         // Invoice_Line_Item__c iline=new Invoice_Line_Item__c();
            ILineList=[select id,Name,Employee_Code__c,Total__c,Invoice_Date__c from Invoice_Line_Item__c where Employee_Code__c=:ecode
                        AND CALENDAR_MONTH(Invoice_Date__c)=:month AND CALENDAR_YEAR(Invoice_Date__c)=:year ];
            for(Invoice_Line_Item__c IL : ILineList)
            {
              rev.Revenue_Without_ST__c=IL.Total__c;
            }
        }
           
    }
 
    }
Here is my  test class but showing error and not executing properly
@isTest
public class testRevenue {
        static testMethod void testMethod1()  {
 InvoiceCategory__c InvC = newInvoiceCategory__c(name = 'Test1');    
                  insert InvC;                      
Invoice_Type__c InvT = new Invoice_Type__c(name = 'Test2');                   
  insert  InvT;
Salary_Type__c SalT = new ISalary_Type__c(name = 'Test2');                   
  insert  SalT
       
            Test.StartTest();               
                Revenue__c rev= new Revenue__c();
                rev.ECode__c='Test0';
                InvoiceCategory__c invC = new InvoiceCategory__c
                List<SelectOption> listInvCt = rev.InvoiceCategory__c();
                List<SelectOption> listInvTy = rev.Invoice_Type__c();
                List<SelectOption> listSalTy = rev.Salary_Type__c();
                rev.SelInvoiceCategory__c ='Test1';
                rev.SelInvoice_Type__c ='Test2';
                rev.SelSalary_Type__c ='Test3';
                rev.Salary_Processed_Month__c=system.today();
Test.StopTest();
        }
    }

Here is my  test class but showing error and not executing properly
@isTest
public class testRevenue {
        static testMethod void testMethod1()  {
 InvoiceCategory__c InvC = newInvoiceCategory__c(name = 'Test1');    
                  insert InvC;                      
Invoice_Type__c InvT = new Invoice_Type__c(name = 'Test2');                   
  insert  InvT;
Salary_Type__c SalT = new ISalary_Type__c(name = 'Test2');                   
  insert  SalT
       
            Test.StartTest();               
                Revenue__c rev= new Revenue__c();
                rev.ECode__c='Test0';
                InvoiceCategory__c invC = new InvoiceCategory__c
                List<SelectOption> listInvCt = rev.InvoiceCategory__c();
                List<SelectOption> listInvTy = rev.Invoice_Type__c();
                List<SelectOption> listSalTy = rev.Salary_Type__c();
                rev.SelInvoiceCategory__c ='Test1';
                rev.SelInvoice_Type__c ='Test2';
                rev.SelSalary_Type__c ='Test3';
                rev.Salary_Processed_Month__c=system.today();
Test.StopTest();
        }
    }
 
Laraib_JafriLaraib_Jafri
What error are you getting?