0

I have 2 class A and B. A has code for Http Callout and from B we are calling A's class method which has callout code. So should we write mock test class for A only or do we have to write mock test for both the classes?

0

You can write one test class for class B and you need to include mock class where you need to specify the response inside mock class. Include this in test class and run this and confirm the code coverage. This is enough for deployment to Production.

Hope it answer your question!!

| improve this answer | |
0

You only need to create single mock for Class A and then when you run your unit test for class B when it comes to HTTP Callout part in class A it will do that mock.

1) Class B calls method from Class A with Callout 2) When test comes to HTTP Callout it will implement the mock 3) Unit test continues as usual.

I hope this helps you.

| improve this answer | |
  • Hi Franjo,When I am running the test class for class B, it is giving error as : Methods defined as TestMethod do not support Web service callouts and this is becasue it is going to the callout class. Kindly help me to short it out. – Anoop Sep 24 '19 at 13:57
  • You should have Test.StartTest & Test.StopTest somewhere in your test class. Try putting your mock callout between them. Something like this: Test.StartTest Test.setMock(HttpCalloutMock.class, new YourHttpCalloutMockImpl()); //Your test code Test.StopTest – Franjo Gregoric Sep 25 '19 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.