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
Devendra Hirulkar 3Devendra Hirulkar 3 

System.AssertException: Assertion Failed: Expected: 2.5, Actual: 0 this error

in my test class the (System.AssertException: Assertion Failed: Expected: 2.5, Actual: 0)error shows what is proble 
the below is my test class


@istest
public class myclass 
{
     static testMethod void veriflyStudentupdation()
    {
        Student__c student = new Student__c(Name='Sam',Roll_No__c=2.5,Address__c='silod');
        {
            insert student;

            class__c newClass = new class__c(student__c = student.Id, Roll_No__c= '2');

            test.startTest();

            insert newClass;
            System.debug('Test Started.,..');

            test.stopTest();
            System.debug('Test Completed.,..');

            student__c upd_student = [Select Id,Roll_No__c  from student__c where id = :student.Id];
            system.assertEquals(2.5, upd_student.Roll_No__c );
        }    

    }   
}
Best Answer chosen by Devendra Hirulkar 3
Deepak Kumar ShyoranDeepak Kumar Shyoran
You can solve this error simply by putting 0 in place of 2.5 like 
 system.assertEquals(0, upd_student.Roll_No__c );

but your problem is as you are firing SOQL to retrieve the same Student records which you have created above with roll No 2.5 but you are getting 0 instead of 2.5, that might be because you may have some validation rule, trigger or workflow rule which updates your roll no, please check that first.

All Answers

Deepak Kumar ShyoranDeepak Kumar Shyoran
You can solve this error simply by putting 0 in place of 2.5 like 
 system.assertEquals(0, upd_student.Roll_No__c );

but your problem is as you are firing SOQL to retrieve the same Student records which you have created above with roll No 2.5 but you are getting 0 instead of 2.5, that might be because you may have some validation rule, trigger or workflow rule which updates your roll no, please check that first.
This was selected as the best answer
Devendra Hirulkar 3Devendra Hirulkar 3
thanks deepak its work