The next step in improving our service testing process is to write some helper methods that allow us to configure our service tests to user our service. These helper methods will be used in each of the test projects to cut down the preparation required in each project.
There are two methods we are going to write:
- Configure Method
- Configure…Service
Configure Method
This method is all about reducing effort when handling response documents.
void ConfigureMethod (const char* const Method)
{
lr_save_string (Method, "Method") ;
lr_save_string(lr_eval_string ("{Method}Response"), "Response");
lr_save_string(lr_eval_string ("{Method}Result"), "Result");
}
The first line is used to set the value that is passed into the service call and therefore needs to exactly match an operation on the service contract. The usage is like this:
ConfigureMethod ("GetDataUsingDataContract") ;
The next two lines are designed to make it easier when extracting information out the response document.
lr_save_string(lr_eval_string ("{Method}Response"), "Response");
lr_save_string(lr_eval_string ("{Method}Result"), "Result");
Allowing us to go from:
lr_xml_extract
(
"XML={response}",
"FastQuery=Envelope/Body/GetDataUsingDataContractResponse/GetDataUsingDataContractResult/BoolValue",
"XMLFragmentParam=BoolValue",
LAST
);
lr_xml_extract
(
"XML={response}",
"FastQuery=Envelope/Body/GetDataUsingDataContractResponse/GetDataUsingDataContractResult/StringValue",
"XMLFragmentParam=StringValue",
LAST
);
to:
lr_xml_extract
(
"XML={response}",
"FastQuery=Envelope/Body/{Response}/{Result}/BoolValue",
"XMLFragmentParam=BoolValue",
LAST
);
lr_xml_extract
(
"XML={response}",
"FastQuery=Envelope/Body/{Response}/{Result}/StringValue",
"XMLFragmentParam=StringValue",
LAST
);
The primary goal is removing is the need to type in the “GetDataUsingDataContractResponse” and “GetDataUsingDataContractResult” value all the time. This is useful if you have extract routines that work on multiple operations that return the same object but have different response names (because they filter in different ways for example).
Configure…Service
The configure service methods are used to prepare a service for use. Because we are getting to the point where our web service calls have no mention of any particular service; are going to need somewhere to configure the necessary values to make them work.
We do this in the Configure..Service methods. All methods take the following format: ”Configure…Service” where the elipses represent that full name of the service with all unsupported charactes removed.
Examples:
- ConfigureMyTestingService
- ConfigureAddressService
All services configurations are coded in the one location. This means that you can specify any service to test simply by calling the appropriate Configure…Service method.
void ConfigureMyTestingService (void)
{
lr_set("Service1", "Service");
lr_set("WSHttpBinding_IService1", "Binding") ;
lr_set("Distributedlife.MyService.Service.xml", "TempFile") ;
lr_set(GetHostIpAddress (), "HostIpAddress") ;
}
The next step configures as set of parameters based on the specified binding. The information to be set is all taken from either service test configuration or the web.config configuration.
lr_set("Service1", "Service");
lr_set("WSHttpBinding_IService1", "Binding") ;
There are two places to get these settings. The first two lines are used by HP Service Test to identify the service that has been added into the project. The best place to get this information is from service test. In your function click on add service and then add in any operation you want. It’ll look like this:
web_service_call
(
"StepName=GetDataUsingDataContract_102",
"SOAPMethod=Service1|WSHttpBinding_IService1|GetDataUsingDataContract",
"ResponseParam=response",
"Service=Service1",
"ExpectedResponse=SoapResult",
BEGIN_ARGUMENTS,
END_ARGUMENTS,
BEGIN_RESULT,
END_RESULT,
LAST
);
From our example and this is all on line 2 we have our service name followed by the binding and then the operation.
"SOAPMethod=Service1|WSHttpBinding_IService1|GetDataUsingDataContract",
Take the service name and binding name and add it to your configuration.
The rest of the configuration is any value you want set for your service. Each of my service tests makes use of a temp file for some operations and knowing the IP address is useful for logging and auditing testing.
|
|
Ryan Boucher is a Software Inquisitor and is passionate about it. You can find a whole raft of articles and anecdotes about software testing and other topics he gets excited about. |
| Tags |