Happy Business Starts Here

Master

I want to know about unit test of Apex class using Order builder

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:

 

5 REPLIES 5
Support SME

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 √

Guru

Re: I want to know about unit test of Apex class using Order builder

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.

Maggie Longshore
Support SME

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 √

Highlighted
Master

Re: I want to know about unit test of Apex class using Order builder

Hi @MaggieL@doyeli

 

I see, Mock can not be used.
It is a pity that I can not aim for full coverage.
But I learned that it is okay to use Test.isRunningTest()
I am going to imitate your way too. Thank you!

Support SME

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 √