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
IGateIGate 

Reg: Test class Code coverage

I have a class like this:

How can i write test class for this.

Please hellp me.

 

public class aaPage78 {
 public List<selectList> lists {get; set;}
 public aaPage78() {
  lists = new List<selectList>();
  for (Integer i = 0; i < 5; i++) {
   lists.add(new selectList(i));
  }
 }
 public PageReference test() {
  return null;
 }
 public class selectList {
  Integer intValue;
  String[] countries = new String[]{};
  public selectList(Integer intValue) {
   this.intValue = intValue;
  }
  public List<SelectOption> getItems() {
   List<SelectOption> options = new List<SelectOption>();
   options.add(new SelectOption('Value:' + intValue + ' - US','Label:' + intValue + ' - US'));
   options.add(new SelectOption('Value:' + intValue + ' - CANADA','Label:' + intValue + ' - Canada'));
   options.add(new SelectOption('Value:' + intValue + ' - MEXICO','Label:' + intValue + ' - Mexico'));
   return options;
  }
  public String[] getCountries() {
   return countries;
  }
  public void setCountries(String[] countries) {
   this.countries = countries;
  }
 }
}

 

 

Test Class:

 

I wrote the following test class to cover the above class.

But it gives only 52% code coverage. The red marked code did not cover.

 

@istest
private class testaapage78
{
    public static testmethod void m1()
    {
        aaPage78 obj=new aaPage78();
        obj.test();
    }
}

 

 

Can any one help me to covert the red marked code.

 

Best Answer chosen by Admin (Salesforce Developers) 
shra1_devshra1_dev

Add these lines in your test method 

aaPage78.selectList obj2 = new aaPage78.selectList(123);

obj2.getItems();

obj2.getCountries();

string[] count;

obj2.setCountries(count);

 

Regards,

Shravan

All Answers

shra1_devshra1_dev

Add these lines in your test method 

aaPage78.selectList obj2 = new aaPage78.selectList(123);

obj2.getItems();

obj2.getCountries();

string[] count;

obj2.setCountries(count);

 

Regards,

Shravan

This was selected as the best answer
IGateIGate

public class abcd
     {
      public void m1()
      {
      Attachment myAttach = new Attachment();
      myAttach.ParentId = '001900000063kAB';//Id of the object to which the page is attached
      myAttach.name = 'attachment';
      PageReference myPdf = Page.one;//myPdfPage is the name of your pdf page
      myAttach.body = myPdf.getContentAsPdf();
      insert myattach;  
      }
      
      static testmethod void testm1()
      {
          abcd obj1=new abcd();
          obj1.m1();
      }
     }

 

Hi how can i conver the red marked line.

hmoh1920hmoh1920
Hello

I am new to apex development, how to make an extension for controllerOpportunity In order  to have all information to generate a PDF
Thanks




SFDC_LearnerSFDC_Learner

use this:

<apex:page controller="Opportunity" renderas="PDF">