distributedlife

passionate about everything

Improving HP Service Tests Part 5 great fault expectations Published by Ryan Boucher @ 11:55 pm

In Part 4 we made a substantial change to how we write service tests. Those that have followed my direction in their own environment will have noticed that we can no longer control whether or not we are expecting a SoapFault or a SoapResult. You may have been using AnySoap which is ignoring a useful HP Service Test feature.

I’ve got the solution and it makes our tests a bit more explicit about our expectations. This is a good thing; the more someone can gather about the expected behaviour of the test, from the test, the better.

Rather than hard coding our expectations into the web request we want to get a setup that looks a bit like this:


SetDefaultParameters () ;

FaultExpected () ;

CallService () ;

The benefit is that anyone reading the test will see that we are expecting a fault. If we don’t want a fault then we use the following code. Note that we don’t need any coding effort for services requests that don’t fault.


SetDefaultParameters () ;

CallService () ;

To achieve this setup we need to make some small changes to our pipeline.

The first change is in SetDefaultParameters; here we setup the default state for our service; which is a “SoapResult”. We store this in the ServiceFaultState parameter


void SetDefaultParameters (void)
{
    lr_set ("SoapResult", "ServiceFaultState") ;

From here we write a new method called FaultExpected that sets the ServiceFaultState parameter to SoapFault. We don’t ever use the setting AnySoap. This allows anything through the gate and our services should behave in a deterministic way.


void FaultExpected (void)
{
    lr_save_string ("SoapFault", "ServiceFaultState") ;
}

Finally with all that written we need to change each and every service request to date. Thankfully this can be done using a find and replace. We want to go from any of the following setups:


"ExpectedResponse=SoapFault",

"ExpectedResponse=SoapResult",

"ExpectedResponse=AnySoap",

To


"ExpectedResponse={ServiceFaultState}",

And in the context of a full web service call:


web_service_call
(
    "StepName={Service}::{Method}",
    "SOAPMethod={Service}|{Binding}|{Method}",
    "ResponseParam=response",
    "Service={Service}",
    "ExpectedResponse={ServiceFaultState}",
    BEGIN_ARGUMENTS,
    END_ARGUMENTS,
    BEGIN_RESULT,
    END_RESULT,
    LAST
);

Tomorrow, I’ll talk a bit about how to validate service faults.

My Mug 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 , , , , , , ,