You need to sign in to do that
Don't have an account?
Alireza Seifi
How can I create a test for my code.
I'm new to Acc Seed and I was worndering how I can create a unit test for my code: and my code covered drop from 95 to 0 when I used developer console to resave, I'm not sure what is causing that.
Any help would be greatfully aprreciated.
global with sharing class DigitalChecksChargeController { public DigitalChecksChargeController(ApexPages.StandardController stdController) { } @RemoteAction public static String createCheck(String email, Decimal amount, String firstName, String lastName, String semail, String description) { return CheckbookAPI.createCheck(email, amount, firstName, lastName, semail, description); } }I'm getting "methods defined as TestMethod do not support Web service callouts"
Any help would be greatfully aprreciated.
Testmethod do not support callout webservice,
Option 1:
Please skip the call of service in webservice class and use the dummy data of response of callouts using Test.istestRunning().
Test class cannot be used to test Web service callout. The Test.isRunningTest() method is a useful method to bypass web service callouts when running automated test cases that would otherwise fail.
For example, in any wsdl2apex generated classes find the WebServiceCallout.invoke() method calls and then wrap them in an test for Test.isRunningTest(). If the test is false the code can still call invoke as generated. Otherwise the code can simulate the web service response, allowing the test cases to complete.
http://www.eltoro.it/ArticleViewer?id=a07A000000NPRjNIAX
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_callouts_wsdl2apex_testing.htm
http://boards.developerforce.com/t5/Apex-Code-Development/how-to-write-test-class-for-webservice-method/m-p/625245#M115307
http://blog.wdcigroup.net/2012/08/salesforce-web-service-callout-test-class/
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Option 2:
Test Web Service Callouts
Generated code is saved as an Apex class containing the methods you can invoke for calling the web service. To deploy or package this Apex class and other accompanying code, 75% of the code must have test coverage, including the methods in the generated class. By default, test methods don’t support web service callouts, and tests that perform web service callouts fail. To prevent tests from failing and to increase code coverage, Apex provides the built-in WebServiceMock interface and the Test.setMock method. Use WebServiceMock and Test.setMock to receive fake responses in a test method.
Specify a Mock Response for Testing Web Service Callouts
When you create an Apex class from a WSDL, the methods in the auto-generated class call WebServiceCallout.invoke, which performs the callout to the external service. When testing these methods, you can instruct the Apex runtime to generate a fake response whenever WebServiceCallout.invoke is called. To do so, implement the WebServiceMock interface and specify a fake response for the Apex runtime to send. Here are the steps in more detail.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex_testing.htm
---------------------------------------------------------------------------------------------------------------------
Also follow the below Links for on similar post:
https://developer.salesforce.com/forums/?id=906F000000094EyIAI
https://developer.salesforce.com/forums/?id=906F0000000BVqxIAG
https://developer.salesforce.com/forums/?id=906F0000000AhBYIA0
https://developer.salesforce.com/forums/?id=906F000000093EuIAI
https://developer.salesforce.com/forums/?id=906F0000000927CIAQ
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing.htm
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm
http://www.greytrix.com/blogs/salesforce/2015/02/02/testing-web-service-callouts/
http://salesforce-evershine-knowledge.blogspot.com/2012/10/testing-web-service-callouts.html
Please do let me know if it helps you.
Regards,
Mahesh
I know I'm asking too much but could you please take a look at my code and see why I'm getting this error? I followed the instructor of the link you provided.
Thanks,
Al