SoapUI API Testing — SOAP and REST Functional Testing with Assertions and Scripts
In this tutorial, you will learn about SoapUI API Testing. We cover key concepts, practical examples, and best practices to help you master this topic.
SoapUI is a comprehensive API testing tool for both SOAP and REST services, supporting WSDL/Swagger imports, functional and load tests, multiple assertion types, and Groovy scripting for custom logic.
What You'll Learn
- How to create SoapUI projects from WSDL and OpenAPI specs
- Writing functional tests with assertions
- Automating tests with Groovy scripts
Why It Matters
Many enterprise systems still use SOAP APIs with complex WS-Security and XML schemas. SoapUI provides the only mature tooling for testing these protocols alongside modern REST endpoints.
Real-World Use
A healthcare integration project connects to a SOAP-based patient records system. SoapUI tests validate XML request signing, WS-Addressing headers, and complex XPath assertions on response bodies.
flowchart LR
A[WSDL/Swagger] --> B[SoapUI Project]
B --> C[Test Suite]
C --> D[Test Cases]
D --> E[Test Steps]
E --> F[Assertions]
F --> G[Pass/Fail Report]
Creating a REST Test in SoapUI
Test a REST endpoint by adding a request step and verifying the response.
// Groovy script test step
import com.eviware.soapui.support.XmlHolder
def request = testRunner.testCase.getTestStepByName("GetProducts")
def response = request.getPropertyValue("response")
def json = new groovy.json.JsonSlurper().parseText(response)
assert json.size() > 0
assert json[0].name != null
log.info("Products returned: ${json.size()}")
testRunner.testCase.setPropertyValue("productCount", json.size().toString())
Expected output: The test passes if at least one product exists and has a name.
SOAP Request with WS-Security
Test a SOAP endpoint with security headers.
// Create SOAP request with WS-Security
def project = testRunner.testCase.testSuite.project
def request = project.getOperationByName("GetPatientRecord")
// Set WS-Security credentials
request.setUsername("svc-account")
request.setPassword("secret")
request.setWssPasswordType("PasswordDigest")
// Assert SOAP response
def holder = new XmlHolder(request.responseContent)
def patientId = holder.getNodeValue("//*:patientId")
assert patientId == "P-12345"
Expected output: SoapUI sends a signed SOAP envelope and validates the response.
Data-Driven Testing with SoapUI
Run the same test case with different data sources.
// Read test data from a CSV
def dataFile = new File("/data/products.csv")
def lines = dataFile.readLines()
lines.eachWithIndex { line, index ->
if (index == 0) return // skip header
def parts = line.split(",")
def productId = parts[0]
def expectedPrice = parts[1]
// Set property and run test case
testRunner.testCase.setPropertyValue("productId", productId)
def step = testRunner.testCase.getTestStepByName("GetProductById")
step.run(testRunner, context)
def price = step.getPropertyValue("responsePrice")
assert price == expectedPrice
}
Expected output: SoapUI iterates through each CSV row and passes if all prices match.
Common Mistakes
| Mistake | Why It's Wrong |
|---|---|
| Not encoding special characters in XML | SOAP requests fail if XML entities are not properly escaped |
| Ignoring namespace prefixes | XPath assertions break when namespaces are not registered |
| Using hardcoded endpoint URLs | Tests fail when environment changes |
| Skipping WS-Security tests | SOAP APIs with security fail without proper signature setup |
| Not cleaning up test data | Tests create side effects that affect other test cases |
| Overusing script assertions | Script assertions are slower and harder to maintain than built-in types |
| Forgetting to disable WSDL validation | Validation slows down test execution for known-good WSDLs |
Practice Questions
- What is a WSDL? A: Web Services Description Language — an XML document that describes SOAP API operations and messages.
- How do you assert an XPath value in SoapUI? A: Add an XPath Match assertion and provide the XPath expression and expected value.
- What is the difference between Mock Service and Virtual Service? A: Mock Service returns static responses; Virtual Service simulates dynamic behavior.
- How do you reuse test steps across test cases? A: Create a test case with reusable steps and use Run Test Case steps to call it.
- What is the SoapUI Pro feature for coverage? A: Coverage Reporter tracks which operations, assertions, and conditions are exercised.
Challenge
Create a SoapUI project for a SOAP calculator API (add, subtract, multiply, divide). Write test cases for each operation with positive and negative inputs. Add assertions for correct results and error messages on division by zero. Parameterize the test data from a CSV file with 20 sets of inputs.
FAQ
What is the difference between SoapUI and Postman?
SoapUI has stronger SOAP/XML support, while Postman is more modern for REST and Graphql APIs.
How do you test SOAP with attachments?
Use MTOM attachments in SoapUI by adding binary content parts to the request.
Can SoapUI do load testing?
Yes, SoapUI includes a LoadTest step that supports concurrent threads, strategies (Burst, Variance), and assertions.
How do you integrate SoapUI into CI/CD?
Use the SoapUI Maven plugin (smartbear-soapui-maven-plugin) or the command-line test runner.
What is a SoapUI project file?
An XML file (.xml) that contains all test suites, test cases, endpoints, and configurations.
How do you use environment variables in SoapUI?
Define properties in a Project Properties file and reference them as ${propertyName}.
What are SoapUI assertions?
Validation steps that check response content, status codes, XPath/XQuery values, and Compliance with schemas.
Mini Project
Build a SoapUI project for a SOAP-based order management API. Import the WSDL and create test suites for: creating an order (201), retrieving an order (200), updating order status (200), listing orders with date filters (200), and handling invalid order IDs (404). Use data-driven testing with 10 CSV rows. Add load tests with 25 concurrent users for 5 minutes.
What's Next
Next, explore API testing with Cypress for frontend-integrated API test automation.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro