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:
src/test/resources/adder-soapui-project.xml
The POM for the adder-it module contains the following:
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.prystasj.adder</groupId>
<artifactId>adder</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>adder-it</artifactId>
<name>adder Integration Testing</name>
<description>Integration testing with soapUI.</description>
<build>
<plugins>
<plugin>
<groupId>eviware</groupId>
<artifactId>maven-soapui-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<projectFile>src/test/resources/adder-soapui-project.xml</projectFile>
<host>localhost</host>
<port>8080</port>
</configuration>
<executions>
<execution>
<id>soap-integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
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:
<pluginRepository>
<id>eviwarePluginRepository</id>
<url>http://www.eviware.com/repository/maven2/</url>
</pluginRepository>