Saturday, August 14, 2010

Maven & soapUI: Testing a Service

In a previous post, I demonstrated the creation of the business logic for an adding web service, that when given a list of numbers, returns their sum. The goal for me was to create a simple service so I can try out automated testing of the service using soapUI from Maven.

In this post, I'll show how I can run the test suite for the service. In the next post, hopefully I'll demonstrate how we can expose the service in Tomcat using Mule.

The created a test suite, when run, produces the following results as demonstrated by the service's log:

INFO  [http-8080-1][2010-07-07 11:23:34,981] - Sum of: [2, 2] = 4
INFO [http-8080-1][2010-07-07 11:23:35,109] - Sum of: [1, 2, 3] = 6
INFO [http-8080-1][2010-07-07 11:23:35,133] - Sum of: [1, 2, 3, 4] = 10
INFO [http-8080-1][2010-07-07 11:23:35,148] - Sum of: [0, 1] = 1
INFO [http-8080-1][2010-07-07 11:23:35,167] - Sum of: [0, 0] = 0
INFO [http-8080-1][2010-07-07 11:23:35,221] - Sum of: [] = 0

In the adder service project, I exported the project containing a test suite to a new integration testing module, adder-it, as:


The POM for the adder-it module contains the following:

<?xml version="1.0" encoding="utf-8"?>
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
<name>adder Integration Testing</name>
<description>Integration testing with soapUI.</description>

To run the tests, with the service up and running locally on port 8080, invoke Maven with:

$ mvn integration-test

Below is some of the build output statements from a test run:

[INFO] [soapui:test {execution: soap-integration-test}]
soapUI 3.5.1 Maven2 TestCase Runner
19:31:31,085 INFO [WsdlProject] Loaded project from [file:/home/prystasj/workspace/prystasj/mule/adder/adder-it/src/test/resources/adder-soapui-project.xml]
19:31:31,713 INFO [SoapUITestCaseRunner] Running soapUI tests in project [adder]
19:31:31,734 INFO [SoapUITestCaseRunner] Running soapUI testcase [Add_2_to_2]
19:31:31,750 INFO [SoapUITestCaseRunner] running step [Add_2_to_2]
19:31:33,305 INFO [SoapUITestCaseRunner] Assertion [SOAP Response] has status VALID
19:31:33,306 INFO [SoapUITestCaseRunner] Assertion [Contains] has status VALID
19:31:33,306 INFO [SoapUITestCaseRunner] Finished running soapUI testcase [Add_2_to_2], time taken: 1543ms, status: FINISHED
19:31:33,307 INFO [SoapUITestCaseRunner] Running soapUI testcase [Add_1_to_2_to_3]
19:31:33,385 INFO [SoapUITestCaseRunner] Project [adder] finished with status [FINISHED] in 1664ms

To access the soapUI Maven plugin, add the following plugin repository to your settings.xml: