I have an apex class A. I'm calling the function of B class from within A.
class A{
B bobj=new B(); B.function2();
function1(); //within class A
}
This function1 and function2 are http calls to 2 diff rest services.
I wrote a test class with httpcallmockouts for the both function1 and function2. So the order goes like this inside APex Test class-
B objB=new B();
HttpResponse res = CalloutB.getInfoFromExternalService();
A objA=new A(); HttpResponse res = CalloutA.getInfoFromExternalService();
//Till this point my test runs successfully for http calls mock
Test.startTest();
objA.function1();
//Here I get an error http callout not supported for test methods for function2 of B class.
//If I change the order above to
//A objA=new A();
//HttpResponse res = CalloutA.getInfoFromExternalService();
//B objB=new B();
//HttpResponse res = CalloutB.getInfoFromExternalService();
//Then I get error http callout not supported for test methods for function1 of A class.
Test.stopTest();
So, how do you test the http call from within another's class function calls in the first class.
Aucun commentaire:
Enregistrer un commentaire