API tests

How to test legacy SOAP APIs systematically

SOAP services often operate for years and support invoicing, warehouse operations or data exchange with partners. Documentation may be outdated and test coverage weak even though the impact of a defect is high. Systematic API tests help reduce risk during both maintenance and modernisation.

Why test coverage tends to be weak

When a SOAP service changes infrequently, a team may postpone its tests. A request also contains an XML envelope, headers, namespaces and a body, making manual case preparation more time-consuming than it is for a simple request carrying JSON data.

At the same time, the team may be planning to replace the service in the future and does not want to invest in a large new suite. If the migration is delayed, however, an important process remains without adequate feedback. A defect may not appear on screen. It can produce an incorrect invoice amount, an unmatched payment or an unprocessed batch.

How we address it

SOAP can be tested as systematically as REST. Tests can be written, for example, in Python with pytest, allowing legacy and modern APIs to use the same approach to versioning, execution and reporting.

We build coverage around these checks:

If the service depends on an external system that is not available in the test environment, it can be replaced with a controlled simulation, or mock. Separate integration tests then also verify the real connection where it is available.

The suite can be integrated into CI/CD and run for relevant changes or before a release. Depending on the risk, a failure may alert the team or stop deployment. This kind of check is particularly useful when the service changes infrequently and its dependencies are not fully documented.

Start with a specific WSDL and SOAP version

Obtain the WSDL, its imports and the XSD schemas in use from the service owner. Record their version or checksum alongside the application version. In WSDL 1.1, a port associates a specific address with an interface binding. Check the selected port, binding and destination address as well as the operation name. A test client must not accidentally adopt a production address from an old description.

SOAP 1.1 and 1.2 are not interchangeable settings for a client. The SOAP 1.1 HTTP binding uses text/xml and the SOAPAction header. SOAP 1.2 XML messages use application/soap+xml, whose action parameter is optional under RFC 3902. Avoid copying headers between versions without checking the contract. Also verify the envelope namespace, authentication method and timeout.

If the client cannot load a schema or authenticate, test preparation has failed. The operation has not yet been verified. Distinguish this from the service rejecting a correctly prepared request.

Compare XML by meaning

Comparing an entire response as text can fail after a harmless prefix change. Under the XML namespace rules, an element’s name consists of its namespace URI and local name. The prefix itself is not its identity. Conversely, the same local name in another namespace can identify a different element.

Use a namespace-aware parser and check specific values: order identifier, quantity, currency and status. Validation against an XSD checks schema conformity. It does not establish that the correct order exists or that the customer was authorised to perform the operation.

Include missing and empty values according to the contract. A service rule must determine the expected result, rather than a tester’s assumption. For dates and amounts, agree on the format, time zone and precision. Do not strip spaces or decimal places from every value just to make comparisons pass.

Distinguish SOAP Faults from transport errors

An HTTP status, a SOAP Fault and the outcome of a business operation are different pieces of information. An HTML error page from a proxy is not a valid service response. Successful HTTP transport alone does not confirm that an order was accepted.

In SOAP 1.2, a Fault requires Code and Reason, while Detail is optional. Check the stable code and agreed error data. Explanations can have language variants, so exact text equality may be an unsuitable condition. The SOAP 1.2 HTTP binding distinguishes, for example, Sender with status 400 and Receiver with status 500. Do not expect every Fault to carry the same HTTP status.

Sender generally requires the request to be corrected. A later attempt after Receiver may succeed, but that does not make repeating a write safe. After losing a response, first check the outcome using the agreed identifier. If the service does not support safe retries, an uncertain outcome needs an agreed resolution procedure. SOAP itself does not guarantee that an order is created exactly once.

A short model: creating an order

Consider a test operation called CreateOrder. In this model, it accepts item TEST-A, quantity 2 and client reference REQ-A. The rules require a known product, a positive quantity and one order per business request. This is an illustrative contract to adapt to your service.

Situation What the test should verify
Valid request One order exists with item TEST-A and quantity 2, and the response carries its identifier.
Unknown product The agreed rejection is returned and no order exists.
Quantity 0 The agreed error is returned and no partially created order remains.
Response lost after sending The test first checks the outcome through REQ-A. Any supported safe retry does not create a second order.

A contract can return a business-rule failure through a Fault or a normal response with a rejection status. A test should not impose the same mechanism on every error. Verify order state through an available read interface or another agreed source, rather than relying solely on the first response. Use separate test data so another concurrent run cannot change the result.

Python clients, evidence and the scope of checks

Pytest organises and runs tests. Building SOAP requests requires a client library or a custom HTTP and XML layer. For example, Zeep is a Python client for SOAP 1.1 and 1.2. Choose according to the contract, security headers and dependency versions in use. One successful documentation example does not verify your service.

On failure, retain the operation name, contract version, environment, HTTP status, error code and run reference. Keep passwords, tokens and complete XML containing personal data out of reports. Record the relevant request and response sections after redacting sensitive values.

The test tool also processes XML. Check parser settings and external-resource access against OWASP’s XXE guidance. Protections vary by parser. A failure to enable a required protection must not be silently ignored. A functional suite does not cover an entire security audit.

What you gain

Automated checks provide repeatable feedback when a legacy service changes. The team can learn sooner whether the service returns the expected XML, error states and results of important operations.

Tests can supplement the WSDL and documentation with concrete examples of expected behaviour. They do not, however, replace the interface description or knowledge of business rules.

Defects in this layer may therefore be detected during an interface test rather than from an incorrect invoice or unprocessed batch in production.

Next step

Start with a list of the most important operations, dependencies and known error states. You can review the proposed coverage in a no-obligation consultation as part of our API testing service.

Related topics

You might also be interested in

You can detect errors in the business logic more quickly directly through the API

Functional, integration and contract testing of REST, SOAP or GraphQL interfaces with the possibility of connection to the CI/CD pipeline.