Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Coverage #9

Closed
vipultaylor opened this issue Feb 11, 2013 · 11 comments
Closed

Test Coverage #9

vipultaylor opened this issue Feb 11, 2013 · 11 comments

Comments

@vipultaylor
Copy link

Hi Andy,

First of all - thank you for such a great resource on using the metadata api. I have tried playing around with it and got some satisfying results. Just wanted to ask if you managed to write any test cases for the classes? I have been struggling to do so and any help will be hugely appreciated.

Regards
Vipul

@afawcett
Copy link
Contributor

Sorry for the late reply. I've not written any tests, it would be quite an undertaking to cover and mock all the XML requests and responses needed to coverage this API. What others have done is commented out the bits their own tests (for controller methods etc) are not needing. If you need some more help on covering the bits remaining I can add some extra notes to the readme if you like. Let me know.

@vipultaylor
Copy link
Author

thanks Andrew for the response. I managed to write the test case covering it up. Thanks for all your help though.

@me-hemantgupta
Copy link

To cover web service callouts we can use the WebServiceMock interface and the Test.setMock method which are built-in in Apex. following URL will be useful for it.

http://salesforce-evershine-knowledge.blogspot.in/2012/10/testing-web-service-callouts.html

For my case the doInvoke() method in implementation for WebServiceMock, just returns null.

@vipultaylor
Copy link
Author

Thanks :)

@cbrao
Copy link

cbrao commented Apr 1, 2013

Thank you so much. I am able to make wrapper class over Metadata API and manage custom objects and fields with ease.

@afawcett afawcett closed this as completed Apr 1, 2013
@cbrao
Copy link

cbrao commented Apr 19, 2013

I am struck with packaging, because I could get only 20% coverage in for metadata service class. My wrapper class got 90%. Can any one help me if they have any code to test coverage MetadataService.

@vipultaylor
Copy link
Author

You could undertake multiple options to increase the test coverage

  1. You could comment out the sub-classes / code which you do not require thereby reducing the size of the executable code and writing test cases for only code that is required in your code.
  2. If you do not want to comment out, since 95% of the code is just sub classes - you could just instantiate an object of each class which would cover up the code for that class.
    example - MetadataService.CustomObject object = new MetadataService.CustomObject();

To cover web service callouts (for the functions such as retrieve/updateMetadata etc. under the MetadataPort class) you can use the WebServiceMock interface and the Test.setMock method which are built-in in Apex. Following URL will be useful for it.

http://salesforce-evershine-knowledge.blogspot.in/2012/10/testing-web-service-callouts.html

Hope that helps.

@afawcett
Copy link
Contributor

Good advice @vipulpahwa, @cbrao does this help you?

@cbrao
Copy link

cbrao commented Apr 22, 2013

I tried the above two ways...but not successful.

I tried WebServiceMock interface callouts. But it is covering only mock class not Metadata service.

Any example code with updateMetadata method will be highly appreciated.

@afawcett
Copy link
Contributor

afawcett commented May 5, 2013

I've now managed to get 100% coverage for the MetadataService.cls via MetadataServiceTest.cls, please refresh both of these and you should be all set. BTW, this took me quite a few hours to get to the bottom, since there is in fact a platform bug with only covering inner classes in tests, I'm going to raise this. However with a small workaround (which I've included in the above files) it is working. The workaround will also be fine to retain once Salesforce fix the problem, so you should be good to go! Sorry for the issues.

@cbrao
Copy link

cbrao commented May 6, 2013

Thank you so much..it worked like a charm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants