- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi all
Please advise me: Is it possible to use "Mock" when using Order Builder?
I am a beginner in Apex development.
I currently develop Apex classes using Order Builder on SFDC.
In parallel, I am also developing a test class for my class.
I know that I can not callout web services from the test class.
Therefore, I learned that I use "Mock" for test:
https://trailhead.salesforce.com/en/modules/apex_integration_services/units/apex_integration_soap_ca...
I succeeded in reproducing the example of the above article.
I tried to apply this example to my situation as well.
I created a class that only executes Zuora.zApi.zlogin() and that Mock class.
After that, I linked the test class to the Mock class.
I executed the test with expectation.
However, the error message "Methods defined as TestMethod do not support web service callouts" is displayed.
Mock seems not to be working properly.
Is it possible to use Mock when using Order Builder?
If I can not use Mock, please advise me what alternatives are available.
* I know that "@isTest" must be given "(SeeAllData = true)". I read here:
https://community.zuora.com/t5/API/quot-Zuora-zAPIException-Please-upload-Zuora-WSDL-at-first-quot/m...
--
What I've noticed:
- https://knowledgecenter.zuora.com/CA_Commerce/I_Development_Resources/B_Order_Builder/D_Programming_... There is a section "Unit Tests and Code Coverage". That is, I can test even when I use Order Builder.
- The explanation linked from "Unit Tests and Code Coverage" seems to be avoiding by not calling web service. In other words, can not I use Mock?https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
- There is an inner class called HttpCalloutMockImplementation in the zApi class. Am I using this?
- Apex seems to have Interface called StubProvider. Am I using this?
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
I do not beleive there is a way to 'mock' the callouts as they are internal to the code in ZQuotes. We would have to have full access to their code such that we knew which callouts to provide mock results for.
I work around this by creating the result object in my code in the case of test:
List<Zuora.zApi.SaveResult> results; if(!Test.isRunningTest()){ results = zApiInstance.zupdate(objs); logCurrentCallout('UpdateZObjects'); } else { results = new List<Zuora.zApi.saveResult>(); Zuora.zApi.saveResult testSaveResultSuccess = new Zuora.zApi.saveResult(); testSaveResultSuccess.success=true; results.add(testSaveResultSuccess); }
This allows my test to pass although it is extremely limited.
If there was a true mocking framework for Salesforce similar to rhinoMocks we could have full test coverage.
You can see where I asked for better information here last year.
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
Re: I want to know about unit test of Apex class using Order builder
HI @yamasaki1ma I am checking on this with internal teams. But I would like to request @MaggieL to share any input that she might have in this regard.
Thank you
Doyeli
If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
I do not beleive there is a way to 'mock' the callouts as they are internal to the code in ZQuotes. We would have to have full access to their code such that we knew which callouts to provide mock results for.
I work around this by creating the result object in my code in the case of test:
List<Zuora.zApi.SaveResult> results; if(!Test.isRunningTest()){ results = zApiInstance.zupdate(objs); logCurrentCallout('UpdateZObjects'); } else { results = new List<Zuora.zApi.saveResult>(); Zuora.zApi.saveResult testSaveResultSuccess = new Zuora.zApi.saveResult(); testSaveResultSuccess.success=true; results.add(testSaveResultSuccess); }
This allows my test to pass although it is extremely limited.
If there was a true mocking framework for Salesforce similar to rhinoMocks we could have full test coverage.
You can see where I asked for better information here last year.
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
Re: I want to know about unit test of Apex class using Order builder
Thank you @MaggieL
If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
Re: I want to know about unit test of Apex class using Order builder
Thank you for the update @yamasaki1ma
Doyeli
If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √