Monday 23 January 2012

Mock Service Integration Testing with SoapUI and Maven

Now the days mock testing is very common in all developments, usually we mock the object behaviors and use them in Unit tests.

 When it comes to web services testing, just mocking the object is not good enough to test. We actually have to mock the behavior at SOAP message level. It is good practice to test against mock services before actually doing the integration test against the actual service. 

Using SoapUI, one approach to do this is, 

1. Create a Mock service Project in SoapUI project using the WSDL
2. Define mock request and responses.
3. start the mock service in SoapUI
4.  run your tests against that.

you can read for step by step example to create and start mock services. 

This may be helpful during the development in developer machine, but when we want to include this tests as part of automated tests and to execute in continues integration tests. The better approach could be to include the starting and stopping of the mock services without installing the SoapUI. This can be achieved using SoapUI maven plugin. 

  1. Create a mock service project in SoapUI project using WSDL (refer
  2. Define Mock requests and responses.
  3. copy the SoapUI mock services project into your classpath.
  4. Include the following in you pom file

This will start the mock services at the start of the test phase and stop at the end of the test phase. Now you can execute the tests as part of the automated unit tests against this mock services to ensure more reliable code.

<noBlock>true</noBlock> is for automated tests, otherwise manual intervention is required to stop the mock service.


Post a Comment