Use Test.isRunningTest to skip the callout as callout invoked from the test class will always gives an excetion. Put a condition before your logic for call out.
if (!Test.isRunningTest())
{
// do callout
}
else
{
// Prepare your fake callout result
}
@isTest
private class testClass()
{
private static isTestMethod void testApexClass()
{
//data creation
//If controller class has a standard controller then create one instance of it
//create Controller class instance
test.startTest()
instanceOfClass.invokeMethodToTest();
//assert your results
test.stopTest()
}
private static isTestMethod void testApexTrigger()
{
//data creation
test.startTest()
// dml action to fire the trigger
//assert your results
test.stopTest()
}
}
Am doing this correctly and my test runs , but my trigger is calling an apex class methos that calls an http web service so when I run the test it gives me in the log:
FATAL_ERROR|System.TypeException: Methods defined as TestMethod do not support Web service callouts, test skipped
so it skips the test because it has a call to web service so what shoudl I do in this case?
Use Test.isRunningTest to skip the callout as callout invoked from the test class will always gives an excetion. Put a condition before your logic for call out.
if (!Test.isRunningTest())
{
// do callout
}
else
{
// Prepare your fake callout result
}
Ok Thank you, now all is Ok and successfuly deployed , now when I run the calss in the production am getting error that am exceeding the 150 limit for DML stataments ... what am doing is trying to update opportunites in the system... first am getting them all in one statament then doing some modification on each object(opportunity) and update it seperatley... thats why am exceeding the 150 limit.. any idea or work arround?
Use Test.isRunningTest to skip the callout as callout invoked from the test class will always gives an excetion. Put a condition before your logic for call out.
All Answers
Check out the Apex Language Reference - http://www.salesforce.com/us/developer/docs/apexcode/salesforce_apex_language_reference.pdf
Also, in the Search box for this site, search for "unit test." You'll see lots of articles on unit testing.
I can provide you structure
Am doing this correctly and my test runs , but my trigger is calling an apex class methos that calls an http web service so when I run the test it gives me in the log:
FATAL_ERROR|System.TypeException: Methods defined as TestMethod do not support Web service callouts, test skipped
so it skips the test because it has a call to web service so what shoudl I do in this case?
Use Test.isRunningTest to skip the callout as callout invoked from the test class will always gives an excetion. Put a condition before your logic for call out.
Ok Thank you, now all is Ok and successfuly deployed , now when I run the calss in the production am getting error that am exceeding the 150 limit for DML stataments ... what am doing is trying to update opportunites in the system... first am getting them all in one statament then doing some modification on each object(opportunity) and update it seperatley... thats why am exceeding the 150 limit.. any idea or work arround?
This seems to be a problem with your code, you must be using some dml statement in a loop. Please provide the code where you are getting this.
Yes it was aproblem with the code and now fixed.
thank you.
Your welcome Alla