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
Aditya RawatAditya Rawat 

Test class getting failed during deployment with error message System.AssertException: Assertion Failed: Expected: May 2019 Forecast, Actual: Apr 2019 forecast

private static testmethod void getIOWithForecastData_test() 
    {
        listOfScenarioMaster = [SELECT Id, Name, BMI_Scenario_Code__c FROM BMI_Scenario_Master__c WHERE Name LIKE '%Forecast' LIMIT 5];
        listOfBusinessUnitMaster = [SELECT Id FROM BMI_Business_Unit_Master__c LIMIT 1];
        listOfCostMaster = [SELECT Id FROM BMI_Cost_Master__c LIMIT 1];
        Test.startTest(); 
        BMI_BudgetInputControllerLWC.getPreviewWithCostMasterDetails(listOfScenarioMaster[0].Id, listOfBusinessUnitMaster[0].Id, 
                                                                  UserInfo.getUserId(), currencyEUR, listOfCostMaster[0].Id, listOfScenarioMaster[0].BMI_Scenario_Code__c, listOfScenarioMaster[0].Name,1.2);
        BMI_BudgetInputControllerLWC.getPreviewWithCostMasterDetails(listOfScenarioMaster[1].Id, listOfBusinessUnitMaster[0].Id, 
                                                                  UserInfo.getUserId(), currencyEUR, listOfCostMaster[0].Id, listOfScenarioMaster[1].BMI_Scenario_Code__c, listOfScenarioMaster[1].Name,1.2);
        BMI_BudgetInputControllerLWC.getPreviewWithCostMasterDetails(listOfScenarioMaster[2].Id, listOfBusinessUnitMaster[0].Id, 
                                                                  UserInfo.getUserId(), currencyEUR, listOfCostMaster[0].Id, listOfScenarioMaster[2].BMI_Scenario_Code__c, listOfScenarioMaster[2].Name,1.2);
        BMI_BudgetInputControllerLWC.getPreviewWithCostMasterDetails(listOfScenarioMaster[3].Id, listOfBusinessUnitMaster[0].Id, 
                                                                  UserInfo.getUserId(), currencyEUR, listOfCostMaster[0].Id, listOfScenarioMaster[3].BMI_Scenario_Code__c, listOfScenarioMaster[3].Name,1.2);
        BMI_BudgetInputControllerLWC.getPreviewWithCostMasterDetails(listOfScenarioMaster[4].Id, listOfBusinessUnitMaster[0].Id, 
                                                                  UserInfo.getUserId(), currencyEUR, listOfCostMaster[0].Id, listOfScenarioMaster[4].BMI_Scenario_Code__c, listOfScenarioMaster[4].Name,1.2);
                        
        BMI_BudgetInputControllerLWC.getCostMasterData(listOfScenarioMaster[0].Id, listOfBusinessUnitMaster[0].Id);
        
        BMI_BudgetInputControllerLWC.getForecastDataForSpecificCostMaster(listOfCostMaster[0].Id, listOfScenarioMaster[0].Id, 
                                                                       UserInfo.getUserId(), currencyEUR,NULL,NULL,1.2);
        //Rajasekar                                                               
        listOfScenarioMasterBP = [SELECT Id, Name, BMI_Scenario_Code__c FROM BMI_Scenario_Master__c WHERE Name = 'Business Plan' LIMIT 1];
        BMI_BudgetInputControllerLWC.getPreviewWithCostMasterDetails(listOfScenarioMasterBP[0].Id, listOfBusinessUnitMaster[0].Id, 
                                                                  UserInfo.getUserId(), currencyEUR, listOfCostMaster[0].Id, listOfScenarioMasterBP[0].BMI_Scenario_Code__c, listOfScenarioMasterBP[0].Name,1.2);
        Test.stopTest();
        system.assertEquals(May_2019_Forecast, listOfScenarioMaster[0].Name);  // for this line showing failure but the same I've run in my lower sanbox and its run successfully with no error
    }
SwethaSwetha (Salesforce Developers) 
Hi Aditya,

It's possible that the lower sandbox had different data which caused the test to pass. However, in the current environment, the test is failing because the data being used by the test is different. You should update the test to use appropriate data to ensure that it passes in the current environment

You could alter code to reflect
system.assertEquals('Apr 2019 forecast', listOfScenarioMaster[0].Name);

If this information helps, please mark answer as best. Thank you. 
Aditya RawatAditya Rawat

Hi Swetha, thank you for the update below approach I've followed earlier:-

changing the error line for code with system.assertEquals('Apr 2019 forecast', listOfScenarioMaster[0].Name); after running the same Test class I got the failure saying :- System.AssertException: Assertion Failed: Expected: Apr 2019 Forecast, Actual: May 2019 forecast.

 

Looks like  listOfScenarioMaster[0].Name having only the May 2019 forecast only.

Later I've compare the code in my dev where the same line in 392 and the sandbox where the deployment failed the error line was 389.

Hope after refreshing the sandbox the issue get resolved as line of code would be same in DEV as well as in Failure Sandbox.

 

kindly, provide your update if some further changes need to done apart from above scenario.

 

Regards,

Aditya Rawat