Saturday, March 14, 2009

Reuse and Agility Part II - Service Testing

In my previous post I talked about some practical design considerations for achieving reuse and agility in your services. This post is going to focus on another critical element in achieving reuse and agility. That topic is testing.

Testing is one of those topics we don't spend near enough time talking about. Yet testing is probably the most critical element to successful reuse and agility. Being able to test quickly and thoroughly will determine how agile and how reusable the service will be.

There are many roadblocks to testing. Here are some of them in no particular order: Clients, Developers, Project Managers, Managers, Bystanders, Custodial Staff, Butterflies in Japan. The point here is just about everything seems to get in the way of testing. These roadblocks can be navigated successfully if you approach testing a slightly different way.

One way to bake testing into the design process is to go with the Test Driven Design approach. I'm not going into detail about it but here is an article on it if you are not familiar with it. Another way to bake in testing is the use of commercial test suites(Note-the two ideas are not mutually exclusive). There are many quality products available on the market but I'm going to talk about a free one called soapUI.

You might think this article has now turned into a product evaluation but it's not completely. I am going to show how a tool such as soapUI can help you test quickly and effectively. soapUI does have some powerful testing features baked into it which makes creating test cases somewhat easy to do which is really the point of this discussion.

The WSDL interface definition is pretty simple in construct. It basically says you give me this and I'll give you that in response. Beyond that the variation of use cases is left up to other documentation and/or test cases. What I have found with using a tool like soapUI is that the act of creating the test cases help flush out the use cases in more detail. It also allows for the documentation of the test cases and reporting of the results which will be useful later on when demonstrating pass/fail on the interface.

soapUI will allow you to import your WSDL and generate sample test cases prior to ever coding any of the implementation. It even has the ability to mock responses back so you can run the test cases prior to coding. This can be a very powerful concept. At this point variations in the use cases can become visible allowing you time to go back to the clients before a whole lot of work has been done. I think the benefit is obvious here. Better software more closely aligned with what the client actually wants.

Here is a great feature that soapUI offers when generating test cases. The ability to add assertions for each test step very easily. All testing tools let you do this but with soapUI it's just simply and straightforward. Here is a screenshot using XPATH to determine the correct return result. Pretty simple stuff but very useful.



This test case is now invokable by creating a simple mock service within the soapUI tool.



No code has been written but now your test cases are defined and documented. And the big win is they are easy to repeat once the real coding begins, is complete and is changed later on down the road. Simply change the endpoint and fire away. Very simple yet very powerful.

No comments: