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
SSimionSSimion 

Error: Compile Error: Defining type for testMethod methods must be declared as IsTest at line 17 column 33

Hi,

I am trying to Save an Apex Class. Please see below:

public class clsHelpSalesStages{
  
  public List<OpportunityStage> getSalesStages(){
    
    List<OpportunityStage> lstOppStage = [ SELECT MasterLabel, 
                           IsClosed,
                           IsWon, 
                           ForecastCategory, 
                           ForecastCategoryName, 
                           DefaultProbability, 
                           Description
                    FROM OpportunityStage
                    WHERE IsActive = true
                    ORDER BY SortOrder ASC ];
    return lstOppStage;
  }
  
  public static testMethod void testMyController(){ 
    clsHelpSalesStages objOppStage = new clsHelpSalesStages();
    List<OpportunityStage> lstOppStageTest = objOppStage .getSalesStages();
  
    System.assert( lstOppStageTest.size() > 0 );
  }
}

But I am getting the following error message: Error: Compile Error: Defining type for testMethod methods must be declared as IsTest at line 18 column 33

The Apex Class is used to show Opportunity Stages Description on the Home Page.

I can see that - The testMethod keyword is now deprecated, so therefore the error. 

I have tried to use @isTest, but it didn't work.

I've never created an Apex Class before, unfortunately, so I am unable to correct the error message.

Could you please let me know what should I correct?


Thanks.
Best Answer chosen by SSimion
yogesh_patilyogesh_patil
Hello,

Since the class clsHelpSalesStages is used to show Opportunity Stages Description on the Home Page request you to remove the below entire code block from your class.

 public static testMethod void testMyController(){ 
    clsHelpSalesStages objOppStage = new clsHelpSalesStages();
    List<OpportunityStage> lstOppStageTest = objOppStage .getSalesStages();
  
    System.assert( lstOppStageTest.size() > 0 );
  }

and try to save.

All Answers

yogesh_patilyogesh_patil
Hello,

Since the class clsHelpSalesStages is used to show Opportunity Stages Description on the Home Page request you to remove the below entire code block from your class.

 public static testMethod void testMyController(){ 
    clsHelpSalesStages objOppStage = new clsHelpSalesStages();
    List<OpportunityStage> lstOppStageTest = objOppStage .getSalesStages();
  
    System.assert( lstOppStageTest.size() > 0 );
  }

and try to save.
This was selected as the best answer
SSimionSSimion
Thank you. That has worked.