Today I’m going to look at the first step in making tests written with HP Service Test more reusable, reliable, less fragile and closer to how a test should. When service testing you need to be able to spend more time writing code that actively tests the system rather than support code.
The first step involves making good use of Service Tests’ parameterisation. When you start writing service tests you are going to have a lot of the following code lying around:
web_service_call
(
"StepName=Do something",
"SOAPMethod=MyService|MyServiceBinding|MyOperationName",
"ResponseParam=response",
"Service=MyService",
"ExpectedResponse=AnySoap",
BEGIN_ARGUMENTS,
END_ARGUMENTS,
BEGIN_RESULT,
END_RESULT,
LAST
);
It won’t take long before this code become tedious to write. If you have been using Service Test for a while then you also know this can become a maintenance problem.
If you have multiple end points that you want to run the same test against then you have to change the binding in half the tests. If you want to run the same test against a different method or a different service you will require additional changes to the service and the operation.
The first step is define some constants in your vuser_init function:
lr_save_string (“MyService”, “Service”) ;
lr_save_string (“MyServiceBinding”, “Binding”) ;
lr_save_string (“MyOperationName”, “Method”) ;
With that in place you can change your method calls to something more like this:
web_service_call
(
"StepName={Service}::{Method}",
"SOAPMethod={Service}|{Binding}|{Method}",
"ResponseParam=response",
"Service={Service}",
"ExpectedResponse=AnySoap",
BEGIN_ARGUMENTS,
END_ARGUMENTS,
BEGIN_RESULT,
END_RESULT,
LAST
);
The changes are on the first four lines of the function call.
You get the following immediate benefits:
- Multiple bindings only involve changing the binding property and you’ve doubled your tests with no additional work load
- Running the same test against a different operation only involves changing the method property
- Running the same test against a different service once again only involves changing the service property
- You can now remove service end point configurations without a complicated find and remove process. I’ll demonstrate this tomorrow.
When you start testing against lots of services you see the same tests again and again. Now you can make use some cut and paste inheritance and duplicate your tests without too much additional work.
In Part 2 I’ll show you how to reduce the code you write by a little bit more by testing only the focus of the test.
|
|
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 |