You need to sign in to do that
Don't have an account?
VRK
unable to write test class for SOSL searchText
Hi i am unable to write test classs for SOSL searchText ...below is my apex class
public class case_exn {
public Case id{get;set;}
public String searchText{get;set;}
List<Case> results = new List<Case>();
public Boolean IsOwnerSpecific {get;set;}
private ApexPages.StandardController ctrl
public case_exn(ApexPages.StandardController controller)
{
id = (Case)controller.getRecord();
}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('Admin mailbox','Admin Mailbox'));
options.add(new SelectOption('Support Mailbox','Support Mailbox'));
}
public String getSearchText()
{
return searchText;
}
public void setSearchText(String s) {
searchText = s;
}
public List<Case> getResults()
{
return results;
}
public pageReference search() {
results = (List<Case>)[FIND :searchText RETURNING Case(CaseNumber,Type, Subject, Priority,Status,CreatedDate,SLA_Flag__c,Owner.Name ];
}
my Test clas:
@isTest
public class TestsearchCaseVFPage {
private static testMethod void testSoslFixedResults()
{
Case obj=new Case(Type='test',Subject='selfService',Priority='medium',Status='Inprogress');
insert obj;
ApexPages.StandardController sc = new ApexPages.StandardController(obj);
case_exn testAccPlan = new case_exn(sc);
Id [] fixedSearchResults= new Id[testAccPlan.Id];
Test.setFixedSearchResults(fixedSearchResults);
//test for searching account in list
Test.startTest();
results = SoslService.search(obj.searchText);
Test.stopTest();
//assertion
System.assertEquals(testAccPlan.Id, results[0][0].Id, 'Account Ids should match');
}
But test class Code not working and coverage also very low....can u pls check and help on this
REgard
sekhar
public class case_exn {
public Case id{get;set;}
public String searchText{get;set;}
List<Case> results = new List<Case>();
public Boolean IsOwnerSpecific {get;set;}
private ApexPages.StandardController ctrl
public case_exn(ApexPages.StandardController controller)
{
id = (Case)controller.getRecord();
}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('Admin mailbox','Admin Mailbox'));
options.add(new SelectOption('Support Mailbox','Support Mailbox'));
}
public String getSearchText()
{
return searchText;
}
public void setSearchText(String s) {
searchText = s;
}
public List<Case> getResults()
{
return results;
}
public pageReference search() {
results = (List<Case>)[FIND :searchText RETURNING Case(CaseNumber,Type, Subject, Priority,Status,CreatedDate,SLA_Flag__c,Owner.Name ];
}
my Test clas:
@isTest
public class TestsearchCaseVFPage {
private static testMethod void testSoslFixedResults()
{
Case obj=new Case(Type='test',Subject='selfService',Priority='medium',Status='Inprogress');
insert obj;
ApexPages.StandardController sc = new ApexPages.StandardController(obj);
case_exn testAccPlan = new case_exn(sc);
Id [] fixedSearchResults= new Id[testAccPlan.Id];
Test.setFixedSearchResults(fixedSearchResults);
//test for searching account in list
Test.startTest();
results = SoslService.search(obj.searchText);
Test.stopTest();
//assertion
System.assertEquals(testAccPlan.Id, results[0][0].Id, 'Account Ids should match');
}
But test class Code not working and coverage also very low....can u pls check and help on this
REgard
sekhar
All Answers