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
Anna SuganthiAnna Suganthi 

System.AssertException: Assertion Failed: Expected: , Actual: null

I have a RestClient test class. In the following part I get this error,
static testmethod void testGet() { 
        RestClientSpy spy = new RestClientSpy();
        
        spy.send(RequestMethods.GET.name(), '/services/data', null);
        
        System.assertEquals(1, spy.getSendCount());
        System.assertEquals(null, spy.getHttpRequest().getBody()); 
        System.assertEquals('GET', spy.getHttpRequest().getMethod()); 
    }

"System.AssertException: Assertion Failed: Expected: null, Actual:"
I tried different things to make it work, still am unable to figure it out. Can anyone help me in this please?
TIA.
Adilson Arcoverde JrAdilson Arcoverde Jr
Hi Anna,

I think this line
System.assertEquals(null, spy.getHttpRequest().getBody());
should be
System.assertNotEquals(null, spy.getHttpRequest().getBody());

Your code is trying to assert if spy.getHttpRequest().getBody() is equal to null. Wouldn't you like to check if request body is not equal to null?.

Hope you find this solution usefeul. If it does please mark as Best Answer to help others developers too.

Regards.

 
Suraj Tripathi 47Suraj Tripathi 47
Hi Anna Suganthi,

Make sure that your Expected and Actual Value should be the same, check that spy.getHttpRequest().getBody() will return null if you expect the null.
you can get help from this :

https://help.salesforce.com/articleView?id=000318949&type=1&mode=1 (https://help.salesforce.com/articleView?id=000318949&type=1&mode=1)

https://developer.salesforce.com/forums/?id=906F0000000AhESIA0

If you find your Solution then mark this as the best answer.

Thank you!

Regards,
Suraj Tripathi