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 http://www.soapui.org/Service-Mocking/mocking-soap-services.html 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.
- Create a mock service project in SoapUI project using WSDL (refer http://www.soapui.org/Service-Mocking/mocking-soap-services.html)
- Define Mock requests and responses.
- copy the SoapUI mock services project into your classpath.
- Include the following in you pom file
<plugin>
<groupId>eviware</groupId>
<artifactId>maven-soapui-plugi n</artifactId>
<configuration>
<projectFile>${basedir}/ target/myservice-soapui-mock-project.xml</projectFile>
<noBlock>true</noBlock>
</configuration>
<executions>
<execution>
<id>soapui-test</id>
<phase>test</phase>
<goals>
<goal>mock</goal>
</goals>
</execution>
</executions>
</plugin>
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.
0 comments:
Post a Comment