Backend Development 4 min read

Automating Mock Test Data Generation with Python and XML

This article explains how beginners can build a Python-based tool to automatically generate mock XML test data for various industries, covering the creation of XML nodes using ElementTree's append and SubElement methods, structuring multi-level XML files, and handling file storage and server upload.

360 Quality & Efficiency
360 Quality & Efficiency
360 Quality & Efficiency
Automating Mock Test Data Generation with Python and XML

For newcomers to testing, manually creating large amounts of test data is time‑consuming, so the article proposes an automated mock data tool that improves testing efficiency.

The tool must generate XML files for 12 different industries, each with around two hundred fields, allowing arbitrary node counts and three‑level hierarchical structures.

Python's standard library xml.etree.ElementTree is used; two node‑creation approaches are demonstrated: appending child elements to a root node like a list, and using SubElement to specify a parent directly.

The author recommends using SubElement for nodes at the same level and append when merging nodes into other parts of the tree, enabling flexible construction of complex XML structures.

After mastering these methods, the tool can produce well‑formatted XML with proper line breaks and indentation, and can generate any number of files as needed.

Implementation steps include creating individual XML nodes (code shown in the article’s images), extracting child nodes from a packaged root, and merging them into new nodes to build the desired three‑level hierarchy.

Additional features such as saving files locally, uploading them to a server via the paramiko module, and providing a simple front‑end page complete the tool.

The main challenge encountered was separating common and industry‑specific fields into separate XML nodes and correctly extracting them; understanding the storage structure of encapsulated nodes resolved this issue.

backendPythonAutomationTestingmock-dataXML
360 Quality & Efficiency
Written by

360 Quality & Efficiency

360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.