Testing SOSL
Use Test.setFixedSearchResults
Class
public class MySearchClass{
public Static void doSearch(String search){
List<List<Sobject>> searchResult;
searchResult=[FIND :search IN ALL FIELDS RETURNING Account];
if(searchResult!=null){
System.debug('in if'+searchResult);
searchResult=[FIND :search IN ALL FIELDS RETURNING Account];
}
else{
System.debug('in else'+searchResult);
searchResult=[FIND :search IN ALL FIELDS RETURNING Account];
}
}
}
Test Class
@isTest
public class TestMySearchClass{
private static testMethod void testMeth(){
Account acc = new Account(Name='testBaljeet');
insert acc;
Test.setFixedSearchResults(new List<Id>{acc.id});
MySearchClass.doSearch('test');
}
}
No comments:
Post a Comment