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
SFDC@ChennaiSFDC@Chennai 

Test Class for Negative part

HI

I wrote test class .
when i give the method name its covering only if part , else part is not covering
I need to cover the else part in test class

In test class I called the method as update();

My code is 

public PageReference update() {
  List < Forecast_Revenue_Report__c > getCheckEmpty = [SELECT Amount__c, Month__c, opp_id__c FROM Forecast_Revenue_Report__c WHERE opp_id__c = : this.oppId];
  if (getCheckEmpty.size() == 0) {
   return null;
  } else {
   List < Forecast_Revenue_Report__c > Output = [SELECT Amount__c, Month__c, opp_id__c FROM Forecast_Revenue_Report__c WHERE opp_id__c = : this.oppId];

   if (Output.size() > 0) {
    if (this.month1.contains(Output[0].Month__c)) {
if (Output.size() >= 1) {
      this.amount1 = Output[0].Amount__c;
     }}



Thanks in Advance
Fabien TaillonFabien Taillon
You need to create 2 methods in your test class, one which will test your IF, and a second one which will test your ELSE.
To get in the IF, you need to create data in your test method that match your conditions, so an Opportunity, Forecast_Revenue_Report__c, and to set this.oppId so that the query return lines.