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
Rolando EstevesRolando Esteves 

Problem with testmethod

Im currently working on my testclass but when I do the calls its not covering the for loop inside my method. How do you test the code lines inside the for loop.

 

Code to be tested:

 

   public List<String> getLst() 
        {
            for(Product__c prod: [SELECT Product_Logo__c FROM Product__c ORDER BY Name])
            {
              imageTag = prod.Product_Logo__c;
              strt = imageTag.indexOf('src=',0) + 5;
              ed = imageTag.lastIndexOf('alt=') - 2;
              tmp = imageTag.substring(strt,ed);
              img_Lst.add(tmp);
            }
         
            return img_Lst;
        }

 

Best Answer chosen by Admin (Salesforce Developers) 
asish1989asish1989

Hi

   will you make sure that you have written test method like this

    

@isTest(SeeAllData=true)
public class TestDataAccessClass {
Product__c prdct = new Product__c(somerequirefield = value , Product_Logo__c = 'some value whose size > 7');
insert prdct;
yourclssname obj = yourclass();
...............
......
Did this post answers your question If so please mark it solved.

All Answers

Jia HuJia Hu
Did you use existing data in the org. or make the test data by yourself.

If you use existing data for test, make sure your for loop can get at lease one Product__c record to process.
asish1989asish1989

Hi

   will you make sure that you have written test method like this

    

@isTest(SeeAllData=true)
public class TestDataAccessClass {
Product__c prdct = new Product__c(somerequirefield = value , Product_Logo__c = 'some value whose size > 7');
insert prdct;
yourclssname obj = yourclass();
...............
......
Did this post answers your question If so please mark it solved.
This was selected as the best answer