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
Amol ChAmol Ch 

Test class not cover code coverage Please guide

Here is my apex class which is call from custom button contan javascript code
global class CreateOpty{

WebService static String CreateOptywithps(String Id)
{
List<Patient_Services__c> ps= new List<Patient_Services__c>();
List<Rate_Card__c> rcard=new List<Rate_Card__c>();
List<sked__Job__c> joblist=new List<sked__Job__c>();
List<sked__Job__c> joblistnw=new List<sked__Job__c>();
Set<OpportunityLineItem> olilist=new Set<OpportunityLineItem>();
List<OpportunityLineItem> olilist1=new List<OpportunityLineItem>(); 
List<Opportunity> oplist=new List<Opportunity>();
List<Account> accname = new List<Account>();
Integer extid;
String RecNamePodwP,RecNameAudwP,RecNameDiteticscwP,RecNameDivTrpwP,RecNameMntHlthwP,RecNameOccTrpwP,RecNameOptmwP,RecNamePhytrpwP,RecNamePhyTrpExClswP,RecNameRegNrsewP,RecNameSpchTrpwP;
String myeffDate = date.today().format();
Date Nxtoptycreationdate,Closedate;
String BillableCycle,InvoiceSentby,InvoiceSentTo,Accntterms,RateCardtype;
List<Patient_Services__c> psupdlist= new List<Patient_Services__c>();
Map<String, Schema.SObjectType> sObjectMap = Schema.getGlobalDescribe() ;
Map<String,Schema.RecordTypeInfo> recordType = sObjectMap.get('Opportunity').getDescribe().getRecordTypeInfosByName();
ID RtIdPodwP,RtIdAudwP,RtIdDiteticscwP,RtIdDivTrpwP,RtIdMntHlthwP,RtIdOccTrpwP,RtIdOptmwP,RtIdPhytrpwP,RtIdPhyTrpExClswP,RtIdRegNrsewP,RtIdSpchTrpwP;

User vLstUserop = [select id from User where Opportunity_Owner__c=true and IsActive=true LIMIT 1];

ps=[select id,Medicare_Account__c,Emergency_Visit__c,DVA_Code__c,Patient_DVA_Number__c,Patient_Medicare_No__c,Podiatry_Services__c,Job_Start_Datew_otime__c,Dispensing_Footwear_F049__c,DVA_Account__c,Initial_Consultation__c,Subsequent_Consulation__c,RecordType.name,Patient__r.Medicare_Account__c,Patient__r.Medicare_Account__r.Name,Patient__r.DVA_Account__c,Patient__r.DVA_Account__r.Name,Who_to_Invoice__c,Patient_Service_Lunch__c,Patient_Service_Invoice_Duration__c,Job_allocation_count__c,Job_Invoice_Start__c,Job_Invoice_Finish__c,Lunch_Break_Duration_from_Job__c,Job_Billable__c,Job__c,Patient_Service_Invoice_Finish__c,Patient_Service_Invoice_Start__c,Job_Type__c,Resource_Name__c,Service_Type__c from Patient_Services__c where id=:ID ];

joblistnw=[Select id,name,Facility_Patient_Sevices_Count__c,Day_count__c,Added_to_Opportunity__c,Opportunity_Id__c,Job_Start_Datew_otime__c,Job_Finish_Datew_otime__c,Lunch_Break_Duration__c,Job_Invoiced__c,sked__Type__c,sked__Account__c,
Resource_Name__c,sked__Job_Allocation_Count__c,Invoice_Finish__c, Invoice_Duration__c,
Invoice_Start__c,Job_Billable__c,sked__Duration__c from sked__Job__c 
where id=:ps[0].Job__c];

String medaccId = ps[0].Patient__r.Medicare_Account__c;
String MedaccName=ps[0].Patient__r.Medicare_Account__r.Name;
String DVAaccId = ps[0].Patient__r.DVA_Account__c;
String DVAaccName=ps[0].Patient__r.DVA_Account__r.Name;

// Check Record type and assing Id and Name to Variable
if(ps[0].RecordType.name =='Podiatry')
{     RtIdPodwP = recordType.get('Podiatry with Patients').getRecordTypeId();
	  RecNamePodwP=recordType.get('Podiatry with Patients').getName();
}
else if(ps[0].RecordType.name =='Audiology')
     {	RtIdAudwP = recordType.get('Audiology with Patients').getRecordTypeId();
        RecNameAudwP=recordType.get('Audiology with Patients').getName();
      }
	  
else if(ps[0].RecordType.name =='Dietetics')
    {		RtIdDiteticscwP = recordType.get('Dietetics with Patients').getRecordTypeId();
           RecNameDiteticscwP=recordType.get('Dietetics with Patients').getName();
    }
	
else if(ps[0].RecordType.name =='Diversional Therapy')
    { 	RtIdDivTrpwP = recordType.get('Diversional Therapy with Patients').getRecordTypeId();
        RecNameDivTrpwP=recordType.get('Diversional Therapy with Patients').getName();
    }
	
if(ps[0].Who_to_Invoice__c=='Medicare Account')
    {
    rcard=[Select id,Next_Opportunity_Creation_Date__c,Which_Rate_to_use_withpatients__c,Footwear_Dispensed__c,Emergency_Visit__c,PricebookEntryId__c,Job_Type__c,Assessment__c,Travel__c,Report__c,Treatment_Rate__c,Menu_Review__c,Hourly_Rate__c,Other__c,Next_Billable_Date__c,Opportunity_Creation_Frequency__c,Invoice_sent_by__c,Invoice_sent_to__c,Account_Terms__c,Rate_Card_Type__c from Rate_Card__c where Account_Name__c='Department of Human Services' AND Job_Type__c=:ps[0].Job_Type__c AND Rate_Card_Type__c=:ps[0].Service_Type__c ];
    }
else
    {
    rcard=[Select id,Next_Opportunity_Creation_Date__c,Which_Rate_to_use_withpatients__c,Footwear_Dispensed__c,Emergency_Visit__c,PricebookEntryId__c,Job_Type__c,Assessment__c,Travel__c,Report__c,Treatment_Rate__c,Menu_Review__c,Hourly_Rate__c,Other__c,Next_Billable_Date__c,Opportunity_Creation_Frequency__c,Invoice_sent_by__c,Invoice_sent_to__c,Account_Terms__c,Rate_Card_Type__c from Rate_Card__c where Account_Name__c='Department of Veteran Affairs' AND Job_Type__c=:ps[0].Job_Type__c AND Rate_Card_Type__c=:ps[0].Service_Type__c];
    }
    
List<Opportunity> opty=[select Id,Opty_No__c from Opportunity order by CreatedDate DESC limit 1];
for(Opportunity oppty:opty)
    {
    extid=Integer.valueOf(oppty.Opty_No__c)+1;
    }
    
	//Create opportunity and opportunity line item
    if(rcard.size()>0 && joblistnw.size()>0 && ps.size()>0)
    {
    Opportunity newopp =new Opportunity();
    if(ps[0].Who_to_Invoice__c=='Medicare Account')
    newopp.Optycreationbatch__c='Medicare-WP-'+myeffDate+'-'+extid;
    if(ps[0].Who_to_Invoice__c=='DVA Account')
     newopp.Optycreationbatch__c='DVA-WP-'+myeffDate+'-'+extid;
     if(ps.size()>0)
        {
				for(Patient_Services__c pslines:ps)
              {
              OpportunityLineItem oli = new OpportunityLineItem();
						oli.Opportunity =new Opportunity(Optycreationbatch__c=newopp.Optycreationbatch__c);
                        oli.PriceBookEntryId = rcard[0].PricebookEntryId__c;
                        oli.Patient_Service__c=pslines.Id;
                        oli.Provider_Name__c=pslines.Resource_Name__c;
                        oli.Patient_Service_Invoice_Start__c=pslines.Patient_Service_Invoice_Start__c;
                        oli.Patient_Service_Invoice_Finish__c=pslines.Patient_Service_Invoice_Finish__c;
                        oli.Rate_Card__c=rcard[0].Id;
                        oli.UnitPrice = rcard[0].Hourly_Rate__c;
                        oli.Quantity = pslines.Job_allocation_count__c;
                        oli.Patient_Service_Lunch__c=pslines.Patient_Service_Lunch__c;
                        oli.Invoice_Start__c=pslines.Job_Invoice_Start__c;
                        oli.Invoice_Finish__c=pslines.Job_Invoice_Finish__c;
                        oli.Lunch_Break_Duration_from_Job__c=pslines.Lunch_Break_Duration_from_Job__c;
                        oli.DVA_Code__c=pslines.DVA_Code__c;
                        oli.AHP_Type__c=pslines.Podiatry_Services__c;
                    
                     if(pslines.Job_Billable__c ==true)
                     {
                        oli.Job_lkup__c=pslines.Job__c;
                        if(pslines.Emergency_Visit__c == true)
                        {
                            oli.UnitPrice = rcard[0].Emergency_Visit__c;
                            oli.Quantity = pslines.Job_allocation_count__c;
                        }
                          if(pslines.Dispensing_Footwear_F049__c == true)
                        {
                            oli.UnitPrice = rcard[0].Footwear_Dispensed__c;
                            oli.Quantity = pslines.Job_allocation_count__c;
                        }
                         if(pslines.Who_to_Invoice__c=='DVA Account' && pslines.Service_Type__c=='Podiatry' && pslines.Initial_Consultation__c==true && pslines.Subsequent_Consulation__c==true)
                        {
                              oli.UnitPrice = rcard[0].Assessment__c;
                              oli.Quantity = pslines.Job_allocation_count__c;
                        }
                     else
                        {   
                            if(rcard[0].Which_Rate_to_use_withpatients__c=='Always use Treatment Rate')
                             {
                                 oli.UnitPrice = rcard[0].Treatment_Rate__c;
                                 oli.Quantity = pslines.Job_allocation_count__c;
                             }
                           else if(rcard[0].Which_Rate_to_use_withpatients__c=='Always use Menu Review Rate')
                             {
                                 oli.UnitPrice = rcard[0].Menu_Review__c;
                                 oli.Quantity = pslines.Job_allocation_count__c;
                             }
                        }                       
                    }
                     else
                     {
                        oli.Job_lkup__c=pslines.Job__c;
                        oli.Quantity = pslines.Job_Invoice_Duration__c; 
                        oli.UnitPrice=0;
                     }
						if( (oli.Quantity!=NULL) && (oli.PriceBookEntryId!=NULL))
                        {	olilist1.add(oli);
                             psupdlist.add(pslines);
                         
                        }
             }}
           if(psupdlist.size()>0)
                {
                      newopp.OwnerId=vLstUserop.Id;
                      newopp.stagename='To be reviewed';
                      Nxtoptycreationdate=rcard[0].Next_Opportunity_Creation_Date__c;
                      Closedate=rcard[0].Next_Billable_Date__c;
                      BillableCycle=rcard[0].Opportunity_Creation_Frequency__c;
                      InvoiceSentby=rcard[0].Invoice_sent_by__c;
                      InvoiceSentTo=rcard[0].Invoice_sent_to__c;
                      Accntterms=rcard[0].Account_Terms__c;
                      RateCardtype=rcard[0].Rate_Card_Type__c;
                 }
                      
                 if(ps[0].Who_to_Invoice__c=='Medicare Account')   
                {
                    newopp.Medicare__c = true;
                    newopp.AccountId=medaccId ;
					//Check record type and assign respective name to oppty
                    if(ps[0].RecordType.name =='Podiatry')
                        newopp.Name= MedaccName +'-' + RecNamePodwP + '-'+ Nxtoptycreationdate.format();
               else if(ps[0].RecordType.name =='Audiology')
                        newopp.Name= MedaccName +'-' + RecNameAudwP + '-'+ Nxtoptycreationdate.format();
               else if(ps[0].RecordType.name =='Dietetics')
                        newopp.Name= MedaccName +'-' + RecNameDiteticscwP + '-'+ Nxtoptycreationdate.format();
                if(ps[0].RecordType.name =='Diversional Therapy')
                        newopp.Name= MedaccName +'-' + RecNameDivTrpwP + '-'+ Nxtoptycreationdate.format();
              }
                  
               if(ps[0].Who_to_Invoice__c=='DVA Account')
              {
                    newopp.DVA__c = true;
                    newopp.AccountId=DVAaccId ;
                if(ps[0].RecordType.name =='Podiatry')
                        newopp.Name= DVAaccName  +'-' + RecNamePodwP + '-'+ Nxtoptycreationdate.format();
               else if(ps[0].RecordType.name =='Audiology')
                        newopp.Name= DVAaccName  +'-' + RecNameAudwP + '-'+ Nxtoptycreationdate.format();
               else if(ps[0].RecordType.name =='Dietetics')
                        newopp.Name= DVAaccName  +'-' + RecNameDiteticscwP + '-'+ Nxtoptycreationdate.format();
                if(ps[0].RecordType.name =='Diversional Therapy')
                        newopp.Name= DVAaccName  +'-' + RecNameDivTrpwP + '-'+ Nxtoptycreationdate.format();
              }
                  
                 newopp.closedate=Closedate;
                  newopp.Billable_Cycle__c=BillableCycle;
                  
                  //check Patient service Record type and assign respective record type id to oppty
                    if(ps[0].RecordType.name =='Podiatry')
                        newopp.RecordTypeId=RtIdPodwP ;
               else if(ps[0].RecordType.name =='Audiology')
                        newopp.RecordTypeId=RtIdAudwP ;
               else if(ps[0].RecordType.name =='Dietetics')
                        newopp.RecordTypeId=RtIdDiteticscwP ;
               else if(ps[0].RecordType.name =='Diversional Therapy')
                        newopp.RecordTypeId=RtIdDivTrpwP ;
               
                    /////////////////////
                  
                 newopp.RateCard__c=rcard[0].Id;
                  newopp.Invoice_sent_by__c=InvoiceSentby;
                  newopp.Invoice_sent_to__c=InvoiceSentTo;
                  newopp.Date_From__c=ps[0].Job_Start_Datew_otime__c;
                  newopp.Patient_DVA_No__c = ps[0].Patient_DVA_Number__c;
                  newopp.Patient_Medicare_No__c = ps[0].Patient_Medicare_No__c;
                  newopp.AHP_Type__c= ps[0].Podiatry_Services__c;
                  newopp.Date_To__c=Nxtoptycreationdate;
                  newopp.Service_Type__c=RateCardtype;
                  oplist.add(newopp);
                  psupdlist.clear();
                              
    }
	if(olilist1.size()>0 && oplist.size()>0)
    {
        insert oplist;
        insert olilist1;          
return (medaccId );
}}
And below in test class,as per my knowledge i've created test class and try to cover few apex code line, but it not showing me any test code coverage,
as I am creating test class in correct way or wrong way ? Please guide
Please explain solution and how to write test class for this in brief
 
@Istest(SeeAllData=True)
public class TestCreateOpty3 {
    Static testmethod void CreateOptyTest1()
    {
        Integer extid;
        User vLstUserop = [select id from User where Opportunity_Owner__c=true and IsActive=true LIMIT 1];
          date myDate = date.today();
        Map<String, Schema.SObjectType> sObjectMap = Schema.getGlobalDescribe() ;
            Map<String,Schema.RecordTypeInfo> recordType = sObjectMap.get('Opportunity').getDescribe().getRecordTypeInfosByName();
            ID RtIdPodwP,RtIdAudwP,RtIdDiteticscwP,RtIdDivTrpwP,RtIdMntHlthwP,RtIdOccTrpwP,RtIdOptmwP,RtIdPhytrpwP,RtIdPhyTrpExClswP,RtIdRegNrsewP,RtIdSpchTrpwP;
            String RecNamePodwP,RecNameAudwP,RecNameDiteticscwP,RecNameDivTrpwP,RecNameMntHlthwP,RecNameOccTrpwP,RecNameOptmwP,RecNamePhytrpwP,RecNamePhyTrpExClswP,RecNameRegNrsewP,RecNameSpchTrpwP;       
        RtIdPodwP = recordType.get('Podiatry with Patients').getRecordTypeId();
        RecNamePodwP=recordType.get('Podiatry with Patients').getName();
        RtIdAudwP = recordType.get('Audiology with Patients').getRecordTypeId();
        RecNameAudwP=recordType.get('Audiology with Patients').getName();
        Id MedicareAccRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Medicare Account').getRecordTypeId();                
        
        List<Account> Parentacc= new List<Account>();
        
       Parentacc.add(new Account(RecordTypeId = MedicareAccRecordTypeId, 
                                          Name = 'Department of Human Services',
                                          Account_Address__c = '123 street 123', 
                                          ABN__c = '1236523652',
                                          Email__c = 'test1@test.com', 
                                          Facility_Notification_Opt_Out__c = True,
                                          Is_Admin__c = True,
                                          Active__c = True));
      insert Parentacc;
        
         List<Contact> Con= new List<Contact>();
        Con.add(new contact(FirstName = '',
                              LastName = 'TestContact',
                              accountId = Parentacc[0].id,
                              MobilePhone = '1234567890',
                              email = 'test@skedulo.com',
                              MailingStreet = 'ABC',
                              Active__c = True,
                              MailingCity = 'ABC',
                              MailingState = 'ABC',
                              MailingPostalCode = 'ABC',
                              MailingCountry = 'ABC'));
            insert Con;
            
          Parentacc[0].Account_Contact__c = con[0].id;
          update Parentacc;
        
         List<Account>  acc= new List<Account>();
         acc.add(new Account(RecordTypeId = MedicareAccRecordTypeId,         
                                    Name = 'Medicare Account',
                                    ParentId=Parentacc[0].Id,
                                    Account_Address__c = '123 street 123',
                                    ABN__c = '12345678912',
                                    Email__c = 'test@test.com',
                                    Facility_Notification_Opt_Out__c = True,
                                    Medicare_Number__c = '123456789',
                                    Is_Admin__c = True,
                                    Active__c = True,
                                    Card_Expiry_Date__c = system.today().addDays(10)));
           insert acc; 
        
         sked__Region__c Reg = new sked__Region__c(Name='SYD');
         Reg.sked__Timezone__c='Australia/Sydney';
         insert Reg;
        
         sked__Location__c Loc = new sked__Location__c( Name = 'Test Location',sked__Region__c = Reg.Id,sked__Address__c = 'Test Address' );
         insert Loc;
        
         sked__Resource__c Res = new sked__Resource__c(Name = 'Test Resource', sked__User__c=UserInfo.getUserId(),sked__Primary_Region__c = Reg.Id);
         insert Res;
        
         Patient__c pat1 = new Patient__c(First_Name__c='First', Last_Name__c='Last',Medicare_Account__c=acc[0].id, Location__c=Loc.Id, Patient_Status__c='Active');
         Patient__c[] pat = new Patient__c[]{pat1};     
         insert pat;
        
        List<sked__Job__c> job=new List<sked__Job__c>();         
        job.add(new sked__Job__c(skdate__Finish__c = '20/08/2014 8:30 AM',
                                            skdate__Start__c = '18/08/2014 8:30 AM',
                                            Invoice_Start__c = DateTime.parse('18/08/2014 8:30 AM'),
                                            Invoice_Finish__c = DateTime.parse('20/08/2014 8:30 AM'),
                                            sked__Duration__c = 501,
                                            sked__Region__c = Reg.Id,
                                            sked__Type__c='Podiatry Clinic',
                                            Job_Billable__c =true,
                                            Resource_Name__c=Res.Name));
         
         job.add(new sked__Job__c(skdate__Finish__c = '20/08/2014 8:30 AM',
                                            skdate__Start__c = '18/08/2014 8:30 AM',
                                            Invoice_Start__c = DateTime.parse('18/08/2014 8:30 AM'),
                                            Invoice_Finish__c = DateTime.parse('20/08/2014 8:30 AM'),
                                            sked__Duration__c = 501,
                                            sked__Region__c = Reg.Id,
                                            sked__Type__c='Audiology Clinic',
                                            Job_Billable__c =true,
                                            Resource_Name__c=Res.Name));
            
         insert job;
        
         List<Patient_Services__c> ps= new List<Patient_Services__c>();
         ps.add(new Patient_Services__c(Service_Type__c = 'Podiatry',
                                                Patient__c = pat1.Id,
                                                Job__c = job[0].id,
                                                Who_to_Invoice__c='Medicare Account',
                                                RecordTypeid= '01290000000hN0p',
                                                Patient_Service_Invoice_Start__c=DateTime.parse('18/08/2014 8:30 AM'),
                                                Patient_Service_Invoice_Finish__c=DateTime.parse('20/08/2014 8:30 AM'),
                                                Patient_Service_Lunch__c='10'));
         ps.add(new Patient_Services__c(Service_Type__c = 'Audiology',
                                                Patient__c = pat1.Id,
                                                Job__c = job[1].id,
                                                Who_to_Invoice__c='Medicare Account',
                                                RecordTypeid= '012O000000011Im',
                                                Patient_Service_Invoice_Start__c=DateTime.parse('18/08/2014 8:30 AM'),
                                                Patient_Service_Invoice_Finish__c=DateTime.parse('20/08/2014 8:30 AM'),
                                                Patient_Service_Lunch__c='10'));
                
        insert ps;
        
         List<PricebookEntry > Pricebook=new List<PricebookEntry >();
        Pricebook =[select id from PricebookEntry where IsActive=true limit 1];
         List<Rate_Card__c> rcard=new List<Rate_Card__c>();    
        rcard.add(new Rate_Card__c(Is_Active__c=true,
                                    Rate_Card_Type__c='Podiatry',
                                    Job_Type__c='Podiatry Clinic',
                                    Invoice_sent_by__c='Email',
                                    Invoice_sent_to__c='Account',
                                    PricebookEntryId__c= Pricebook[0].id,
                                    Treatment_Rate__c=100.00,
                                    Account__c = acc[0].Id,
                                    Which_Rate_to_use_withpatients__c='Always use Treatment Rate',
                                    Next_Opportunity_Creation_Date__c=date.parse('18/08/2016')));
        
       
        rcard.add(new Rate_Card__c(Is_Active__c=true,
                                    Rate_Card_Type__c='Audiology',
                                    Job_Type__c='Audiology Clinic',
                                    Invoice_sent_by__c='Email',
                                    Invoice_sent_to__c='Account',
                                    PricebookEntryId__c= Pricebook[0].id,
                                    Treatment_Rate__c=100.00,
                                    Account__c = acc[0].Id,
                                    Which_Rate_to_use_withpatients__c='Always use Treatment Rate',
                                    Next_Opportunity_Creation_Date__c=date.parse('18/08/2016')));
         insert rcard;
        
         List<Opportunity> opty=[select Id,Opty_No__c from Opportunity order by CreatedDate DESC limit 1];
         extid=Integer.valueOf(opty[0].Opty_No__c)+1;
       
        List<Opportunity> newopp=new List<Opportunity>();
         newopp.add(new Opportunity(
         			Optycreationbatch__c='Medicare-WP-'+myDate+'-'+extid,
                     OwnerId=vLstUserop.Id,
                     stagename='To be reviewed',
                     Medicare__c = true,
                     AccountId=acc[0].Id ,
                     Name=  acc[0].Name +'-' + 'Podiatry with Patients' + '-'+ myDate.format(),
                     Invoice_sent_by__c=rcard[0].Invoice_sent_by__c,
                     Invoice_sent_to__c=rcard[0].Invoice_sent_to__c,
                     closedate=myDate,
                     AHP_Type__c= ps[0].Podiatry_Services__c,
                     Date_To__c=rcard[0].Next_Opportunity_Creation_Date__c,
                     Service_Type__c= rcard[0].Rate_Card_Type__c,
                     RecordTypeId=RtIdPodwP,
                     RateCard__c=rcard[0].Id));
        
        newopp.add(new Opportunity(
            						Optycreationbatch__c='Medicare-WP-'+myDate+'-'+extid+1,
                                     OwnerId=vLstUserop.Id,
                                     stagename='To be reviewed',
                                     Medicare__c = true,
                                     AccountId=acc[0].Id ,
                                     Name=  acc[0].Name +'-' + 'Audiology with Patients' + '-'+ myDate.format(),
                                     Invoice_sent_by__c=rcard[0].Invoice_sent_by__c,
                                     Invoice_sent_to__c=rcard[0].Invoice_sent_to__c,
                                     closedate=myDate,
                                     AHP_Type__c= ps[1].Podiatry_Services__c,
                                     Date_To__c=rcard[0].Next_Opportunity_Creation_Date__c,
                                     Service_Type__c= rcard[0].Rate_Card_Type__c,
                                     RecordTypeId=RtIdAudwP,
                                     RateCard__c=rcard[0].Id));
        insert newopp;
                
        List<OpportunityLineItem> oli = new List<OpportunityLineItem>();
          oli.add(new OpportunityLineItem(
                                         OpportunityId =newopp[0].id,
                                         PriceBookEntryId = rcard[0].PricebookEntryId__c,
                                         Provider_Name__c=ps[0].Resource_Name__c,  
                                         Patient_Service__c=ps[0].Id,
                                         Rate_Card__c=rcard[0].Id,
                                         Patient_Service_Invoice_Start__c=ps[0].Patient_Service_Invoice_Start__c,
                                         Patient_Service_Invoice_Finish__c=ps[0].Patient_Service_Invoice_Finish__c,
                                         Patient_Service_Lunch__c=ps[0].Patient_Service_Lunch__c,
                                         UnitPrice = rcard[0].Treatment_Rate__c,
                                         Invoice_Start__c=ps[0].Job_Invoice_Start__c,
                                         Invoice_Finish__c=ps[0].Job_Invoice_Finish__c,
                                         Lunch_Break_Duration_from_Job__c=ps[0].Lunch_Break_Duration_from_Job__c,
                                         AHP_Type__c=ps[0].Podiatry_Services__c,
                                         Quantity = 1,
                                         Job_lkup__c=ps[0].Job__c)
                                         );
       oli.add(new OpportunityLineItem(
                 OpportunityId =newopp[1].id,
                 PriceBookEntryId = rcard[1].PricebookEntryId__c,
                Provider_Name__c=ps[1].Resource_Name__c,  
                 Patient_Service__c=ps[1].Id,
                 Rate_Card__c=rcard[1].Id,
                 Patient_Service_Invoice_Start__c=ps[1].Patient_Service_Invoice_Start__c,
                 Patient_Service_Invoice_Finish__c=ps[1].Patient_Service_Invoice_Finish__c,
                 Patient_Service_Lunch__c=ps[1].Patient_Service_Lunch__c,
                 UnitPrice = rcard[1].Treatment_Rate__c,
                 Invoice_Start__c=ps[1].Job_Invoice_Start__c,
                 Invoice_Finish__c=ps[1].Job_Invoice_Finish__c,
       			 Lunch_Break_Duration_from_Job__c=ps[1].Lunch_Break_Duration_from_Job__c,
       			 AHP_Type__c=ps[1].Podiatry_Services__c,
                 Quantity = 1,
                 Job_lkup__c=ps[1].Job__c));
          insert oli;
        }}


 
Best Answer chosen by Amol Ch
pconpcon
The problem is not the name of your test class, it is the fact that you are not actually calling your class.  For example
 
global class CreateOpty {
    WebService static String createOptywithps(String id) {
        // Do something with Id
        return 'Hello world';
    }
}

Then in your test code
public class TestCreateOpty3 {
    static testMethod void createOptyTest() {
        // Pre setup where id is created

        Test.startTest();

        String result = CreateOpty.createOptywithps(id);

        Test.stopTest();

        System.assertEquals(
            'Hello World',
            result,
            'Did not get the expected result'
        );
    }
}

Also, I do not see any reason why you should be using SeeAllData and if you don't know why you are using it then you shouldn't be using it.

All Answers

pconpcon
The problem is that you're not calling your class at all.  You will want to call the CreateOpty.CreateOptywithps and pass in your Ids.  I would also recommend that you read over these articles [1] [2] [3] [4].

[1] http://www.sfdc99.com/2013/05/14/how-to-write-a-test-class/
[2] http://pcon.github.io/presentations/testing/
[3] http://blog.deadlypenguin.com/blog/2014/07/23/intro-to-apex-auto-converting-leads-in-a-trigger/
[4] http://blog.deadlypenguin.com/blog/testing/strategies/
Amol ChAmol Ch
Hi pcon
I've change the test class name to CreatoptyTest. still i'm not able to view code coverage. please guide where i'm missing
pconpcon
The problem is not the name of your test class, it is the fact that you are not actually calling your class.  For example
 
global class CreateOpty {
    WebService static String createOptywithps(String id) {
        // Do something with Id
        return 'Hello world';
    }
}

Then in your test code
public class TestCreateOpty3 {
    static testMethod void createOptyTest() {
        // Pre setup where id is created

        Test.startTest();

        String result = CreateOpty.createOptywithps(id);

        Test.stopTest();

        System.assertEquals(
            'Hello World',
            result,
            'Did not get the expected result'
        );
    }
}

Also, I do not see any reason why you should be using SeeAllData and if you don't know why you are using it then you shouldn't be using it.
This was selected as the best answer
Amol ChAmol Ch
Hi Pcon,

Thank you very much. your answer is help ful for me, it increse my understanding about test class. previous i dont no about how to actual write or call the class in test class. thanks..!
Kiran ThanuKiran Thanu
Hi folks im not able to cover the catch block with some simple string your valuble time helps me to learn new thing, thanks in advance.

CODE:
 public static String convertEightWords(String str){
        String strchar='';
        try{   
         List<String> elems = str.split(' ');
         if(elems.size() >= 8) {
             for(integer i = 0; i < 8;i++){
                strchar += elems[i] + ' ';
             }
             if (strchar.length() >=80){
                 strchar = str.substring(0, 80);
             }
         }else{
             strchar = str;
         } 
         //strchar = str.substring(0, 80); 
        }
        catch (QueryException ex) {
          insert new IRIS_Apex_Debug_Logs__c(Apex_Class__c = 'IRIS_ReviewSubmit', Type__c = 'UI',
                  Message__c       = System.Label.IRIS_Database_SOQL_Failure,
                  Method__c        = 'convertEightWords',
                  Stack_Trace__c   = ex.getStackTraceString());
      }
        
        system.debug('strchar--'+strchar);
        return strchar;
    }
pconpcon
You'll just want to write a test case that passes in a null this will throw a null pointer exception.
static testMethod void npeTest() {
    String input = null;

    Test.startTest();

    String result = ClassName.convertEightWords(input);

    Test.stopTest();

    System.assertEquals('', result, 'Did not get the expected results');

    List<IRIS_Apex_Debug_Logs__c> logs = [
        select Method__c, Stack_Trace__c
        from IRIS_Apex_Debug_Logs__c
    ];

    System.assertEquals(1, logs.size(), 'Did not get the expected number of logs');
    System.assertEquals('convertEightWords', logs.get(0).Method__c, 'Did not get the right method');
    System.assert(logs.get(0).Stack_Trace__c.contains('null object'), 'Did not get the right stack trace');
    // This may need to change depending on what the stack trace actually contains
}