English 中文(简体)
Mocking Web Service Response | Bundle couple of them in a web app
原标题:

I am working in an enterprise project and my team is responsible for creating front end of the application and there is another team developing webservices and has provided WSDL for all the services that will be available as part of this project. In development phase our local dev environment will point to one of the development box of the team responsible for creating web services. It is quite possible that their dev environment will be shaky in middle of iteration. In order to mitigate that risk, we are using SOAP UI on our local machine and start mocked service and do the development. Whenever we need different flavors of response we modify the local service response XML. This process is running good but i was wondering if there is a way that for each service say i create 10 responses and deploy them as a war on tomcat on one of the machine and my whole development team points to that war which will expose the same service and based on a parameter it can send one response out of the 10 responses bundled in war. i don t want to spend any effort on this. Is there a tool which provides this kind of functionality out of the box.

问题回答

It would make your life easier if you split up your internal architecture a bit. Instead of inflexibly letting the client code rely on an external SOAP service, it would be beneficial to define an interface for internal use. You could call this IServiceProxy or some such name.

Let the client code talk to that interface and use Dependency Injection (DI) to inject an instance of it into the client. This means that for a lot of development usage, you can simply replace this interface with a Test Double (e.g. a Mock).

If you must also have a SOAP service to verify that your SOAP stack works as intended, watch out for the so-called Shared Fixture test smell. A shared test service on a single server would be a Shared Fixture, and it is likely to give you more trouble than it s worth because developers would be stepping over each other and it would be a bottleneck.

A better alternative is to set up a SOAP service on each developer s machine, or, if that s not possible, a dedicated service for each developer.

You can read more about Shared Fixtures and many other test patterns and anti-patterns in the excellent xUnit Test Patterns.

I was in the same situation where testing team wanted to test different scenario, which required mocked service to be modified time to time. Since most of the testing team personal were non technical, I was always bothered to update the soapUI mock suit. To avoid this I created a completely web based a application to mock a service using WSDL. Since it is completely web based testers were able to change the mocked service from their web browsers.

The application is written on top of soapUI framework. It provides features like auto generate dummy response SOAP message and validation etc. The utility also allows to mock a service with delay, this helps for performance testing.

I ve now added the application to SourceForge. Please find in below link

http://sourceforge.net/projects/easymocker/

(Web Service Mocker is an easy to use, completely web based SOAP web service mocking utility. This utility is found very useful in a SOA development environment during unit test, component integration test and non-functional requirement testing.)

I faced the similar problem earlier

We created a mock host web service application using the WSDL for which mock service is required

Stored all different responses in different XML files in server

In web service code we just put switch with unique identifier in the Web Service request and inside switch block we are sending the response from the specific XML file stored in server corresponding to unique identifier

This was possible as the Response were mostly static and will vary with respect to single unique identifier in the request

It took hardly a day to build and deploy this as we had responses handy

Hope this helps you based on the context of your application





相关问题
SoapUI Groovy 方言

我试图阅读即将提出的申请,并根据请求中价值分立的3.0作出模拟反应。 我为此使用了以下大写。

Mocking Entity Context in EF4

I am using VS2010 B2 and EF4 B2 and trying to use Rhino Mocks to mock the entity context generated by EEF. var context = MockRepository.GenerateMock<SomeDBEntities>(); IObjectSet<TxMode> ...

Google Mock for iPhone development?

I have an interesting situation where I am refactoring a bunch of ObjC iPhone code to create a C++ API. I m a novice to C++ and looking into C++ mocking frameworks to augment the work I d done using ...

StrucutureMap RhinoMock Record/Playback, Example needed

I m looking for some examples on how to do the following Mock Tests using StructureMap or Unity with NUnit. I have the following code structure public interface IDAL { List<Model> Method1(...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

Elegant design of simulating a read-only object

I am currently developing an GUI to an embedded system. (I am using GUI to descripe my app opposed to interface to avoid confusion with the progamatic meaning) Context I have created a class which ...

热门标签