You need to sign in to do that
Don't have an account?
fiona gentry
Error at Test class "Non static method cannot be referenced from a static context:"
Hi folks,
while calling a service at test class at Line 58 saying
here is test class code
How to resolve the "Non static method cannot be referenced from a static context:" error
Thanks in advance
Fiona
while calling a service at test class at Line 58 saying
here is test class code
// Set mock callout class Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator()); // Call method to test. // This causes a fake response to be sent // from the class that implements HttpCalloutMock. HttpResponse res = HerokuBanSync.getBANInfoUpdate('990135742'); // Verify response received contains fake values String contentType = res.getHeader('Content-Type'); System.assert(contentType == 'application/json'); String actualValue = res.getBody(); String expectedValue = '{"GSMStackableSOC__c":"false"}'; System.assertEquals(actualValue, expectedValue); System.assertEquals(200, res.getStatusCode());
How to resolve the "Non static method cannot be referenced from a static context:" error
Thanks in advance
Fiona
All Answers
Please use the instance of the HerokuBanSync you created at line 48 like this I hope this help
Can you check what is your method getBANInforUpdate returns?
this is response while debugging
Can you please send me the method and details?
Also expected response from the method getBANInfoUpdate is
Thanks for sharing the code. This gave me huge clarify. Since you haven't shard the test class but this is what you need to do in your test class
Create a mock class which you may already have to this (if need change the setBody as per your need) In the test class please
change this
to this. You can add more fields in SOQL and then assert them with the fake response you get from the mock class.
Let me know if this help. Let me know if you need more assistance with apex.
Good I am glad it is helping you.
Create another moke fail kind of like this.
create another testmethod and put this in there
Let me know, if this help.
lso let me know if you need to learn Apex.
here is class here failmock generator class