0

test case:

    @istest
    public class testcustomreport{
    static testMethod void myUnitTest(){
    list<batch__c> b=new list<batch__c>();
    batch__c ba=new batch__c();
    insert ba;
    b.add(ba);
        Test.startTest();
            // start the test execution context

            // set the test's page to your VF page (or pass in a PageReference)
            Test.setCurrentPage(Page.customreport);

            // call the constructor
            customreport controller = new customreport();
             controller.showlist();
          //   string query='select MOD_Maxi__c,Quote_Line_Item__r.Quote1__r.from1__c,Quote_Line_Item__r.Quote1__r.Order_Received__c,Quote_Line_Item__r.Quote1__c,Quote_Line_Item__r.Name,Quote_Line_Item__r.N_EP_DPI__c, Asked_Qty__c, Unit_Price__c, Max_Quantity__c,batch_value__c,Quote_Line_Item__r.Client_P_N__c,Quote_Line_Item__r.Description__c,Quote_Line_Item__r.Quote1__r.Quote_number_new__c,Quote_Line_Item__r.Quote1__r.name,Quote_Line_Item__r.Quote1__r.Account_Name__c,Quote_Line_Item__r.Quote1__r.Quote_Validity__c,Quote_Line_Item__r.Quote1__r.RFQ_Date__c,Quote_Line_Item__r.Quote1__r.createddate__c,Quote_Line_Item__r.Quote1__r.account_code__c  from  batch__c ';
             string inputtext1='teja';
             string operator;
              string query='select Quote_Line_Item__r.Quote1__r.from1__c,Quote_Line_Item__r.Quote1__r.Order_Received__c,Quote_Line_Item__r.Quote1__c,Quote_Line_Item__r.Name,Quote_Line_Item__r.N_EP_DPI__c, Asked_Qty__c,MOD_Maxi__c, Unit_Price__c, Max_Quantity__c,batch_value__c,Quote_Line_Item__r.Client_P_N__c,Quote_Line_Item__r.Description__c,Quote_Line_Item__r.Quote1__r.Quote_number_new__c,Quote_Line_Item__r.Quote1__r.name,Quote_Line_Item__r.Quote1__r.Account_Name__c,Quote_Line_Item__r.Quote1__r.Quote_Validity__c,Quote_Line_Item__r.Quote1__r.RFQ_Date__c,Quote_Line_Item__r.Quote1__r.createddate__c,Quote_Line_Item__r.Quote1__r.account_code__c  from  batch__c ';
          String[] filters = new String[0];
          if(inputtext1=='alexis de lassat') {
        filters.add(' Quote_Line_Item__r.Quote1__r.from1__c =alexis de lassat');
          }
       }
if(inputtext1=='teja'){
       system.assertEquals(query ,' select Quote_Line_Item__r.Quote1__r.from1__c,Quote_Line_Item__r.Quote1__r.Order_Received__c,Quote_Line_Item__r.Quote1__c,Quote_Line_Item__r.Name,Quote_Line_Item__r.N_EP_DPI__c, Asked_Qty__c,MOD_Maxi__c, Unit_Price__c, Max_Quantity__c,batch_value__c,Quote_Line_Item__r.Client_P_N__c,Quote_Line_Item__r.Description__c,Quote_Line_Item__r.Quote1__r.Quote_number_new__c,Quote_Line_Item__r.Quote1__r.name,Quote_Line_Item__r.Quote1__r.Account_Name__c,Quote_Line_Item__r.Quote1__r.Quote_Validity__c,Quote_Line_Item__r.Quote1__r.RFQ_Date__c,Quote_Line_Item__r.Quote1__r.createddate__c,Quote_Line_Item__r.Quote1__r.account_code__c  from  batch__c  where  Quote_Line_Item__r.Quote1__r.from1__c =teja');
}

            test.stopTest();
    }
    }

controller:

     public list<batch__c> quo{get;set;}       //this is will hold data to be displayed on page
      public void showlist(){ //do not return anything
      string query='select Quote_Line_Item__r.Quote1__r.from1__c,Quote_Line_Item__r.Quote1__r.Order_Received__c,Quote_Line_Item__r.Quote1__c,Quote_Line_Item__r.Name,Quote_Line_Item__r.N_EP_DPI__c, Asked_Qty__c,MOD_Maxi__c, Unit_Price__c, Max_Quantity__c,batch_value__c,Quote_Line_Item__r.Client_P_N__c,Quote_Line_Item__r.Description__c,Quote_Line_Item__r.Quote1__r.Quote_number_new__c,Quote_Line_Item__r.Quote1__r.name,Quote_Line_Item__r.Quote1__r.Account_Name__c,Quote_Line_Item__r.Quote1__r.Quote_Validity__c,Quote_Line_Item__r.Quote1__r.RFQ_Date__c,Quote_Line_Item__r.Quote1__r.createddate__c,Quote_Line_Item__r.Quote1__r.account_code__c  from  batch__c ';
      String[] filters = new String[0];
      if(String.isnotblank(inputtext1)) {
    filters.add(' Quote_Line_Item__r.Quote1__r.from1__c ' + operator + ' : inputText1');
      }
     if(String.isnotblank(inputtext2)) {
    filters.add(' Quote_Line_Item__r.Quote1__r.Quote_number_new__c ' + operator1 + ' : inputText2');
      }
if(!filters.isempty()) {
    query += ' where ' + string.join(filters,' AND ');

I am not getting the code coverage of this statements:

filters.add(' Quote_Line_Item_r.Quote1_r.from1__c ' + operator + ' : inputText1'); filters.add(' Quote_Line_Item_r.Quote1_r.Quote_number_new__c ' + operator1 + ' : inputText2');

can any body help me:

2 Answers 2

1

If other lines have been covered but only these two lines, it's because of your inputtext1 and inputtext2 are whitespace or empty('') or null. With the posted code it's unable to find out whether these fields are null or not.

-2

Try this negative test.

@istest
    public class testcustomreport{
    static testMethod void myUnitTest(){
    list<batch__c> b=new list<batch__c>();
    batch__c ba=new batch__c();
    insert ba;
    b.add(ba);
        Test.startTest();
            // start the test execution context

            // set the test's page to your VF page (or pass in a PageReference)
            Test.setCurrentPage(Page.customreport);

            // call the constructor
            customreport controller = new customreport();
             controller.showlist();
          //   string query='select MOD_Maxi__c,Quote_Line_Item__r.Quote1__r.from1__c,Quote_Line_Item__r.Quote1__r.Order_Received__c,Quote_Line_Item__r.Quote1__c,Quote_Line_Item__r.Name,Quote_Line_Item__r.N_EP_DPI__c, Asked_Qty__c, Unit_Price__c, Max_Quantity__c,batch_value__c,Quote_Line_Item__r.Client_P_N__c,Quote_Line_Item__r.Description__c,Quote_Line_Item__r.Quote1__r.Quote_number_new__c,Quote_Line_Item__r.Quote1__r.name,Quote_Line_Item__r.Quote1__r.Account_Name__c,Quote_Line_Item__r.Quote1__r.Quote_Validity__c,Quote_Line_Item__r.Quote1__r.RFQ_Date__c,Quote_Line_Item__r.Quote1__r.createddate__c,Quote_Line_Item__r.Quote1__r.account_code__c  from  batch__c ';
             string inputtext1='teja';
             string operator;
              string query='select Quote_Line_Item__r.Quote1__r.from1__c,Quote_Line_Item__r.Quote1__r.Order_Received__c,Quote_Line_Item__r.Quote1__c,Quote_Line_Item__r.Name,Quote_Line_Item__r.N_EP_DPI__c, Asked_Qty__c,MOD_Maxi__c, Unit_Price__c, Max_Quantity__c,batch_value__c,Quote_Line_Item__r.Client_P_N__c,Quote_Line_Item__r.Description__c,Quote_Line_Item__r.Quote1__r.Quote_number_new__c,Quote_Line_Item__r.Quote1__r.name,Quote_Line_Item__r.Quote1__r.Account_Name__c,Quote_Line_Item__r.Quote1__r.Quote_Validity__c,Quote_Line_Item__r.Quote1__r.RFQ_Date__c,Quote_Line_Item__r.Quote1__r.createddate__c,Quote_Line_Item__r.Quote1__r.account_code__c  from  batch__c ';
          String[] filters = new String[0];
          if(inputtext1=='alexis de lassat') {
        filters.add(' Quote_Line_Item__r.Quote1__r.from1__c =alexis de lassat');
          }
       }
if(inputtext1=='teja'){
       system.assertEquals(query ,' select Quote_Line_Item__r.Quote1__r.from1__c,Quote_Line_Item__r.Quote1__r.Order_Received__c,Quote_Line_Item__r.Quote1__c,Quote_Line_Item__r.Name,Quote_Line_Item__r.N_EP_DPI__c, Asked_Qty__c,MOD_Maxi__c, Unit_Price__c, Max_Quantity__c,batch_value__c,Quote_Line_Item__r.Client_P_N__c,Quote_Line_Item__r.Description__c,Quote_Line_Item__r.Quote1__r.Quote_number_new__c,Quote_Line_Item__r.Quote1__r.name,Quote_Line_Item__r.Quote1__r.Account_Name__c,Quote_Line_Item__r.Quote1__r.Quote_Validity__c,Quote_Line_Item__r.Quote1__r.RFQ_Date__c,Quote_Line_Item__r.Quote1__r.createddate__c,Quote_Line_Item__r.Quote1__r.account_code__c  from  batch__c  where  Quote_Line_Item__r.Quote1__r.from1__c =teja');
}

            test.stopTest();
    }

static testMethod void myUnitTestNegative(){
    list<batch__c> b=new list<batch__c>();
    batch__c ba=new batch__c();
    insert ba;
    b.add(ba);

   // set the test's page to your VF page (or pass in a PageReference)
            Test.setCurrentPage(Page.customreport);

            // call the constructor
            customreport controller = new customreport();
             controller.showlist();
             string inputtext1='';
             string inputtext2='';
             string operator;
       String[] filters = new String[0];

        filters.add(' Quote_Line_Item__r.Quote1__r.from1__c :’+ inputtext1);
          filters.add(' Quote_Line_Item__r.Quote1__r.Quote_number_new__c :’+ inputtext2);

    }


    }
4
  • hi syed it show the same no improvement
    – Teja
    Mar 14, 2014 at 11:30
  • can you post your controller/trigger? Mar 14, 2014 at 11:34
  • hi it was above check it out
    – Teja
    Mar 14, 2014 at 11:40
  • hi Syed, the answers section should only be used to post answers, if you have an update to your question, it is better to just edit the question and highlight what you have changed in your question.
    – KoenVM
    Mar 14, 2014 at 14:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .