+ Start a Discussion
Kiru535Kiru535 

How to writr Test calsss for below class

Please help me writing test class for below class.

 

public class Cloneopty
{

public final String ForecastStatusIsNewActive = 'New/Active';

public void CloneoptywithIbxline(Id oldOppoID ,Id opportunityId) 
{
List<IBX_Lines__c> ibx =[Select Name,Opportunity__c,IBX_Name__c,Forecast_Status__c,Line_Type__c,Booked_Gross_MRR__c,Booked_Gross_NRR__c,Booked_Net_MRR__c,Booked_Net_NRR__c,Forecast_NRR__c,Forecast_MRR__c from IBX_Lines__c where opportunity__c =:oldOppoID AND Forecast_Status__c='Slipped'];
List<IBX_Lines__c> ibsList = new List<IBX_Lines__c>();
system.debug ('***The ibx is***'+ ibx);
for(IBX_Lines__c ib : ibx)
{
IBX_Lines__c newline = new IBX_Lines__c ();
newline.Opportunity__c= opportunityId;
newline.IBX_Name__c = ib.IBX_Name__c;

newline.Line_Type__c = ib.Line_Type__c;
newline.Forecast_Status__c = ForecastStatusIsNewActive;
newline.Forecast_NRR__c =ib.Forecast_NRR__c;
newline.Forecast_MRR__c =ib.Forecast_MRR__c;
ibsList.add(newline);

}
insert ibsList;
system.debug('***list is****'+ ibsList);
}
}

souvik9086souvik9086

Try this

 

@isTest
public class TestUpdateLead
{
  static testMethod void myTest()
  {

      Cloneopty conObj = new Cloneopty();

      Opportunity opp1 = new Opportunity(Name = 'test');insert opp1;

      Opportunity opp2 = new Opportunity(Name = 'test');insert opp2;

      IBX_Lines__c obj = new IBX_Lines__c(opportunity__c =:opp1.id,Forecast_Status__c='Slipped');insert obj;

      conObj.CloneoptywithIbxline(opp1.id,opp2.id);
  }

}

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

 

sambasamba

@isTest

public class TestCloneOpportunity

{

          @isTest

          public static void testCloneoptywithlbxline()

          {

          //You need to create two opportunity, the first one is Old Opportunity and the other one is new Opportunity.

          Opportunity oldOpportunity = new Opportunity();

          Opportunity newOpportunity = new Opportunity();

          ....

          insert oldOpportunity;

          insert newOpportunity;

          //You need also to create a IBX_Lines__c record. IBX_Lines__c.Opportunity = oldOpportunity.Id and Forecast_Status__c='Slipped'

          CloneOpportunity testOpportunity = new CloneOpportunity();

          testOpportunity.Cloneoptywithlbxline(oldOpportunity.id, newOpportunity.id);

         }

          

}

Kiru535Kiru535

GETTING List has now rows exception 

Please paste me the exact code

souvik9086souvik9086

Modify like this and check what happens

 

@isTest
public class TestUpdateLead
{
  static testMethod void myTest()
  {

      Cloneopty conObj = new Cloneopty();

      Opportunity opp1 = new Opportunity(Name = 'test');insert opp1;

      Opportunity opp2 = new Opportunity(Name = 'test');insert opp2;

      IBX_Lines__c obj = new IBX_Lines__c(IBX_Name__c='test,Line_Type__c='test',Forecast_NRR__c='Test',Forecast_MRR__c='Test',opportunity__c =:opp1.id,Forecast_Status__c='Slipped');insert obj;

      conObj.CloneoptywithIbxline(opp1.id,opp2.id);
  }

}

 

 

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

asish1989asish1989

Try this

@isTest
public class TestUpdateLead
{
  static testMethod void myTest()
  {

      Cloneopty conObj = new Cloneopty();

      Opportunity opp1 = new Opportunity(Name = 'test');
      Date MyDate = Date.newInstance(2013, 07, 06);
      opp1.CloseDate = MyDate;
      opp1.StageName = 'Prospecting';
      insert opp1;

      Opportunity opp2 = new Opportunity(Name = 'test');
      Date MyDate = Date.newInstance(2013, 07, 06);
      opp2.CloseDate = MyDate;
      opp2.StageName = 'Prospecting';
      insert opp2;

      IBX_Lines__c obj = new IBX_Lines__c(opportunity__c =:opp1.id,Forecast_Status__c='Slipped');
      obj.IBX_Name__c = 'test';
      obj.Line_Type__c = 'testvalue';
      //like wise bind all necessary field such as Forecast_Status__c ,Forecast_NRR__c,Forecast_MRR__c,
      insert obj;
      

      conObj.CloneoptywithIbxline(opp1.id,opp2.id);
  }

}