You need to sign in to do that
Don't have an account?
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.
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
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
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.
I am new to apex development, how to make an extension for controllerOpportunity In order to have all information to generate a PDF
use this:
<apex:page controller="Opportunity" renderas="PDF">