You need to sign in to do that
Don't have an account?
dujsu
Question regarding Test Case
Im trying to write a test case for a webservice and could use a nudge. This is probably a VERY basic concept that I am missing. Any assistance is appreciated.
Here is the psuedo webservice that I have built:
global class theWS { global class RequestArguments { webservice string AValue; } global class ResponseArguments { webservice string AID; webservice string AName; } webservice static ResponseArguments[] DescribeObject(RequestArguments Request) { List<ResponseArguments> bList = new List<ResponseArguments>(); if(Request.AValue != null){ List<MyObject__c> bList = new List<MyObject__c>([SELECT ID, Name FROM MyObject where Name = :Request.AValue LIMIT 1]); for (Integer i=0;i<buildList.size();i++) { ResponseArguments ra = new ResponseArguments(); ra.AID = buildList.get(i).ID; ra.AName = buildList.get(i).Name; bList.add(ra); } } return bList; } }
Here is my test case thus far (my question is below):
@isTest private class Test_theWS { static testMethod void test_SimpleRequest() { theWS.RequestArguments reqArgs = new theWS.RequestArguments(); reqArgs.AValue = 'A'; List<theWS.ResponseArguments> blist = theWS.DescribeObject(reqArgs); system.assert(true, bList.size() > 0); } }
QUESTION: Im trying to assign "A" value to reqArgs.AValue, but it doesn't appear to be getting passed in the collection following (DescribeObject(reqArgs)). How do I properly assign a value to reqArgs.AValue?
Thanks ahead of time!
Hi,
Try the below class with test method as reference:
global class theWS
{
global class RequestArguments {
webservice string AValue;
}
global class ResponseArguments {
webservice string AID;
webservice string AName;
}
webservice static ResponseArguments[] DescribeObject(RequestArguments Request) {
List<ResponseArguments> bList = new List<ResponseArguments>();
if(Request.AValue != null){}
/* List<MyObject__c> bList = new List<MyObject__c>([SELECT ID,
Name
FROM MyObject
where Name = :Request.AValue
LIMIT 1]);
for (Integer i=0;i<buildList.size();i++) {
ResponseArguments ra = new ResponseArguments();
ra.AID = buildList.get(i).ID;
ra.AName = buildList.get(i).Name;
bList.add(ra);
}
}*/
return bList;
}
static testmethod void TestAboveCLass()
{
RequestArguments re=new RequestArguments();
ResponseArguments res=new ResponseArguments();
theWS.DescribeObject(re);
//t.ResponseArguments();
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Thank you for the reply. This does not resolve my issue though.
Im still trying to get the for loop to fire off, see below, I realized I misspelled the list name so this may have caused you some confusion since your example is commented out. Its corrected in the example below: