Test data closure generation and runtime writeback reinjection methods, apparatus, devices, and media
By automatically parsing test cases to generate data requirement tags, and utilizing an environment-isolated registry and self-healing process, the problem of lack of closed-loop management of test data in existing technologies is solved, realizing automated closed-loop management of test data and improving test stability and reliability.
Patent Information
- Application Number
- CN202611275939.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-21
- Publication Date
- 2026-11-27
AI Technical Summary
In existing automated testing systems, test data lacks closed-loop management, which leads to reliance on manual intervention in data preparation, errors during cross-environment replication, low reliability of test conclusions, and a lack of automated data status checks and backfilling mechanisms, affecting test stability and the efficiency of problem localization.
By parsing test case files to generate data requirement tags, automatically querying or creating test data using an environment-isolated registry, and capturing runtime data after testing in the backend management class, the data is standardized into constants usable in the front end, realizing a self-healing process and full lifecycle traceability of data.
It achieves automated closed-loop management of test data, improves the stability and reliability of testing, reduces maintenance costs, ensures the traceability of data sources, facilitates rapid problem location, and meets audit compliance requirements.
Smart Images

Figure CN123178254A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of automated testing technology, and in particular to a method, apparatus, device, and medium for closed-loop generation and runtime write-back and re-injection of test data. Background Technology
[0002] In the field of software testing, automated testing systems typically use tools such as Playwright, Selenium, pytest, or API testing frameworks, based on test cases, script directories, or test case records in a test management platform, to perform automated verification of web pages, APIs, or backend management functions. These systems can generate test reports and, to some extent, read test data from static configuration files, CSV files, Excel spreadsheets, or API documentation.
[0003] However, existing solutions often rely on manually pre-configured test data, cross-environment copying, or hard-coded data within scripts. Workflow identifiers, template paths, page access addresses, backend function switches, account status, API interface configurations, and assertion baseline values are typically configured by testers in the target environment before being manually maintained in test scripts or configuration files. Some solutions can automatically generate input values, boundary values, and outliers based on Swagger or OpenAPI documentation, but the generated data usually lacks correlation with the preconditions, target environment, backend runtime state, and frontend page validation of specific test cases, failing to form a closed loop.
[0004] For test scenarios where backend management configurations are strongly correlated with frontend business displays, the current practice is generally to have testers manually modify the backend configurations first, and then have frontend automated scripts read fixed variables for verification. The runtime results generated during the execution of backend management test cases, such as template identifiers, resource paths, function switch states, edit text, API sample code, interface display text, or execution records, lack automatic collection, standardized naming, write-back, and re-injection mechanisms. This makes it impossible for subsequent frontend scripts to confirm whether the data they reference truly originates from the current environment, the current account, and the current test phase.
[0005] Specifically, existing technologies have at least the following drawbacks: First, the preconditions, test data, and expected results in test cases lack unified parsing and labeling. Before executing the test, the system cannot automatically determine what type of resources, status, account permissions, backend configuration, and assertion benchmark need to be prepared, and data preparation still requires manual identification and intervention.
[0006] Secondly, there is a lack of strong binding between test data and the target environment. When testers manually copy resource identifiers, template paths, or backend configurations across environments, it is easy to cause problems such as invalid references, environment contamination, and misuse of data from other environments. When the same set of test cases is executed in different environments, it is often necessary to maintain multiple independent configuration files, which is costly and error-prone.
[0007] Third, the generation of test data, usability verification, registration and logging, configuration backfilling, and script injection are usually scattered across different tools or manual processes. The lack of a traceable closed-loop chain makes it difficult to prove that the data actually used by automated test scripts truly meets the preconditions of the current use case, thus affecting the credibility of the test conclusions.
[0008] Fourth, there are data breakpoints between backend management tests and frontend business tests. Runtime states generated after backend test cases are executed, such as newly created resource identifiers, parameter values after configuration changes, and switch status changes, cannot be automatically converted into constants that can be referenced by frontend scripts. Frontend verification scripts often continue to use old values, hard-coded values, or manually maintained static values, leading to inaccurate verification results.
[0009] Fifth, when test data is deleted, its state shifts, or configuration changes fail to take effect, existing testing frameworks often skip test cases, report failures, or require testers to manually fill in the data. The lack of automatic checks, reconstruction, verification, backfilling, and retry mechanisms for data state makes test stability highly susceptible to environmental factors, resulting in a high false alarm rate in continuous integration scenarios.
[0010] Sixth, existing test reports typically only record the execution results of test cases (pass or fail), with less emphasis on the source of test data, the environment, the operating account, the creation method, the verification results, and the write-back records. If a test fails, locating the cause requires testers to manually review multiple logs and configuration files, leading to low efficiency in problem localization, difficulty in regression testing and reuse, and difficulty in meeting audit compliance requirements.
[0011] There is no effective solution to the above problems in the existing technology. Summary of the Invention
[0012] The technical problem to be solved by the present invention is to provide a method, apparatus, device and medium for closed-loop generation and runtime write-back and re-injection of test data, which realizes automatic generation of test data driven by test cases, management by environment isolation and closed-loop transmission across stages, thereby improving test stability and data traceability.
[0013] In a first aspect, the present invention provides a method for closed-loop generation and runtime write-back and re-injection of test data, comprising the following steps: Step S1: Obtain the test case file, parse the precondition field, test data field, and expected result field in the test case file to obtain the parsing result, and convert the parsing result into a preset format data requirement tag; the preset format data requirement tag includes at least resource type, status requirement, functional characteristics, environment identifier, account identifier, and verification condition; Step S2: Read the current test environment identifier, access the environment isolation data registry corresponding to the current test environment identifier, and use the set fields in the data requirement tag as matching conditions to query whether there is test data that matches all the matching conditions and has a valid registration status. If it exists, perform real-time status detection on the queried test data to confirm that the test data is available in the current target system and meets the status requirements in the data requirement tag. If the real-time status detection confirms that it is available, the queried test data is used as reused test data. If there is no test data with a valid registration status, or if the real-time status detection confirms that it is unavailable, call the business system interface or the backend management interface to create test data that meets the data requirement tag as new test data. Step S3: Perform availability verification on the reused test data or the newly created test data. After the verification is passed, backfill the resource identifier, path information, configuration parameters and assertion benchmark of the test data into the current environment configuration file, record the log information of the backfill operation, the log information includes at least the backfill time, operation account, backfill data item identifier and its value, and dynamically generate a test data module file containing the backfilled test data. Inject the test data module file into the reference path of the automated test script for reference by the backend management test script and the frontend business test script. Step S4: Identify and prioritize the execution of the backend management test script to obtain the first test execution result, capture the runtime data generated by the backend management test script during execution, and normalize the runtime data into runtime constants that can be referenced by the frontend; Step S5: Write the runtime constants back to the current environment configuration file, record the log information of the write-back operation, the log information includes at least the write-back time, operation account, write-back data item identifier and its value, and regenerate the test data module file containing the runtime constants. Inject the regenerated test data module file into the reference path of the front-end business class test script to replace the test data previously referenced by the front-end business class test script. Step S6: Execute the front-end business class test script to obtain the second test execution result, and make the front-end business class test script refer to the backfilled test data and the runtime constants to perform page verification, interface verification or business status verification. Step S7: During the availability verification process of step S3, or during the execution of the test scripts of steps S4 to S6, if it is detected that the test data does not meet the status requirements or verification conditions in the data requirement tag, it is determined that the preconditions are not met and the self-healing process is triggered. The self-healing process includes: re-executing steps S1 to S3 to re-parse the test case fields, rebuild and verify the test data, and retrying the current test case after the verification is passed.
[0014] Secondly, the present invention provides a test data closed-loop generation and runtime write-back and re-injection apparatus, comprising: The parsing and tagging module is used to obtain test case files, parse the precondition fields, test data fields, and expected result fields in the test case files to obtain parsing results, and convert the parsing results into data requirement tags in a preset format; the preset format data requirement tags include at least resource type, status requirements, functional characteristics, environment identifier, account identifier, and verification conditions; The environment isolation registry management module is used to read the current test environment identifier, access the environment isolation data registry corresponding to the current test environment identifier, and use the set fields in the data requirement tag as matching conditions to query whether there is test data that matches all the matching conditions and has a valid registration status. If it exists, real-time status detection is performed on the queried test data to confirm that the test data is available in the current target system and meets the status requirements in the data requirement tag. If the real-time status detection confirms that it is available, the queried test data is used as reused test data. If there is no test data with a valid registration status, or if the real-time status detection confirms that it is unavailable, the business system interface or the backend management interface is called to create test data that meets the data requirement tag as new test data. The verification and backfilling injection module is used to perform availability verification on the reused test data or the newly created test data. After the verification is successful, the resource identifier, path information, configuration parameters and assertion benchmark of the test data are backfilled into the current environment configuration file. The backfilling operation log information is recorded. The log information includes at least the backfilling time, operation account, backfilled data item identifier and its value. The module also dynamically generates a test data module file containing the backfilled test data and injects the test data module file into the reference path of the automated test script for reference by the backend management test script and the frontend business test script. The background execution and runtime capture module is used to identify and prioritize the execution of background management test scripts to obtain the first test execution result, capture the runtime data generated by the background management test scripts during execution, and normalize the runtime data into runtime constants that can be referenced by the front end. The runtime constant write-back and re-injection module is used to write the runtime constants back to the current environment configuration file, record the log information of the write-back operation, the log information includes at least the write-back time, operation account, write-back data item identifier and its value, and regenerate the test data module file containing the runtime constants. The regenerated test data module file is injected into the reference path of the front-end business class test script to replace the test data previously referenced by the front-end business class test script. The front-end execution module is used to execute the front-end business class test script, obtain the second test execution result, and enable the front-end business class test script to reference the backfilled test data and the runtime constants to perform page verification, interface verification or business status verification. The self-healing module is used to determine that the preconditions are not met and trigger the self-healing process if the test data does not meet the status requirements or verification conditions in the data requirement tags during the availability verification process of the verification and backfilling injection module, or during the execution of the test script from the background execution and runtime capture module to the foreground execution module. The self-healing process includes: re-executing the parsing and tagging module to the verification and backfilling injection module to re-parse the test case fields, rebuild and verify the test data, and retry the current test case after the verification is passed.
[0015] Thirdly, the present invention provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in the first aspect.
[0016] Fourthly, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect.
[0017] One or more technical solutions provided by this invention have at least the following technical effects or advantages: (1) This application parses the precondition field, test data field, and expected result field in the test case file and converts them into data requirement tags in a preset format. This enables the system to automatically identify what resources, states, configurations, and assertion benchmarks the current test case requires, and drives the data preparation process accordingly. Compared with the existing technology that requires manual identification and configuration of data requirements, this application avoids the problems of test case skipping, false failures, and frequent manual data addition caused by missing data, thus improving the execution efficiency of automated testing.
[0018] (2) This application maintains an independent data registry for each test environment. Each registration record is bound to its respective environment and account. When querying reusable data, the resource type, tag list, environment, and account must be matched simultaneously, and only records with a valid registration status are returned. Compared with the existing technology of manually copying resource identifiers, template paths, or backend configurations across environments, this application effectively avoids the problems of invalid references, data pollution, and misuse of other environment data caused by environment confusion, so that the same set of test cases can obtain correct test data in different environments.
[0019] (3) After data reuse or creation, this application performs availability verification through methods such as interface calls and page probing to confirm whether resources exist, workflows are published, templates are uploaded, configuration switches are effective, and the number of records reaches the threshold. Only data that passes verification is allowed to be backfilled into the configuration file and injected into the test script. Compared with the existing technology that uses data directly after preparation without validity verification, this application significantly improves the credibility of test conclusions and avoids false passes or invalid failures caused by data not being effective or mismatched status.
[0020] (4) This application sets up a phased execution mechanism for backend management tests and frontend business tests: First, the backend management test script is executed, capturing runtime data such as switch states, configuration parameters, newly created resource identifiers, code snippets, and display text generated during its execution. This data is then standardized into runtime constants with a unified naming format and written back to the current environment configuration file, before being re-injected into the frontend business test script. Compared with the existing technology where backend configuration changes cannot be automatically transmitted to frontend verification and frontend scripts need to manually maintain static expected values, this application achieves automated closed-loop transmission of backend runtime states to frontend verification data, enabling frontend verification to complete the verification based on the latest data generated by this backend execution, thus solving the long-standing problem of data breakpoints across test phases.
[0021] (5) During the data availability verification and test script execution process, this application continuously monitors whether the test data meets the state requirements and verification conditions of the test cases. Once it is found that the resource is missing, the template is removed, the configuration is not effective, or the assertion benchmark is mismatched, the self-healing process of "re-parsing - rebuilding - verification - backfilling - retrying" is immediately triggered, and the invalid data is marked as invalid in the registry. Compared with the existing technology where the test framework only skips test cases, reports failures, or requires manual data filling after data state drift, this application realizes system-level automatic repair when data is abnormal, reduces false alarms and failures caused by environmental factors, and improves the execution stability of automated testing in multi-environment, multi-version, and continuous integration scenarios.
[0022] (6) This application records operation logs at each stage, including data creation, real-time status detection, availability verification, backfilling, runtime capture, write-back, and self-healing. The final test execution report includes at least the data source identifier, environment identifier, account identifier, data creation method, first verification result, second verification result, and write-back operation log. Compared with the existing technology where test reports only record test case execution results and lack data link information, this application makes the entire lifecycle of test data "source—creation—verification—use—change—failure" traceable, which facilitates rapid location of failure causes, regression reuse, and compliance with audit and compliance requirements.
[0023] (7) This application completely extracts the data preparation logic from the specific test script. The system automatically completes the data query, creation, verification, backfilling, and injection based on the test case tags. The test script only needs to import the constant test data module. Compared with the existing technology that hardcodes a large number of resource identifiers, configuration parameters, and assertion benchmarks in the test script, this application enables the same set of test cases to automatically obtain available data in different environments according to the actual state of the environment. It does not require maintaining a separate script or configuration file for each environment, thus reducing script maintenance costs and manpower investment.
[0024] (8) This application incorporates dynamic values such as switch states, edit text, API sample code, display text, and configuration parameters generated during the execution of backend management test cases into a unified write-back chain through runtime data capture and constant write-back mechanisms, enabling the frontend verification script to reference these dynamically generated runtime constants to complete the verification. Compared with the limitations of existing technologies where static test data is difficult to handle dynamic configuration verification scenarios, this application can effectively cover dynamic verification requirements such as automatically backfilling template paths after workflow release, automatically transferring identifiers after resource creation, and automatically verifying the effectiveness of configuration changes, thus broadening the scope of application of automated testing.
[0025] The above description is merely an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention and to implement it in accordance with the contents of the specification, and in order to make the above and other objects, features and advantages of the present invention more apparent and understandable, specific embodiments of the present invention are described below. Attached Figure Description
[0026] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0027] Figure 1 This is a schematic diagram of the device in Embodiment 2 of the present invention. Detailed Implementation
[0028] The overall concept of the technical solution in this application embodiment is as follows: This application proposes a closed-loop generation and runtime write-back and re-injection method for test data in automated testing. This method uses the precondition fields, test data fields, and expected result fields in the test case file as entry points, converting natural language or structured fields into standardized data requirement tags, and binding them to the current test environment, account, resource type, and assertion conditions. Before executing the test, the system first queries the current environment's dedicated registry for reusable resources; if no resources are found or the found resources do not meet the conditions, the system calls the target system interface or backend management interface to automatically create the corresponding workflow, template, backend configuration, or other test resources, and performs availability verification. After successful verification, the creation results are registered in the environment-isolated registry, populated back into the current environment configuration file, and merged into the test data module injected into the automated script.
[0029] This application also sets up a phased execution mechanism for backend management tests and frontend business tests: first, the backend management tests are executed to capture the runtime data generated during their execution; then, the runtime data is normalized into constants that can be referenced by the frontend and written back to the current environment configuration file; subsequently, the test data is re-merged and injected, and the frontend business tests are executed, so that the frontend scripts can directly reference the latest data generated and verified by the backend phase.
[0030] Specific steps may include: S1: Obtain the test case file and parse the fields such as "preconditions", "test data", and "expected results"; S2: Convert the parsing results into standardized data requirement tags, which include resource type, status, functional characteristics, environment identifier, account identifier, and verification conditions; S3: Read the current test environment identifier, access the data registry corresponding to the environment, and query whether there is reusable data that meets the data requirement tag; S4: If the query is successful, perform status verification on the successful data; if it is unsuccessful or the verification fails, call the business system interface or the backend management interface to create test data. S5: Write the creation result to the data registry, recording the resource ID, page path, tag, source use case, creation time, environment, account, and verification status; S6: Verify whether the test data meets the preconditions of the test cases through interface or page probing, such as whether the resources exist, whether the workflow has been published, whether the template has been uploaded, whether the input parameters exist, whether the number of records has reached the threshold, and whether the configuration switch is effective. S7: After successful verification, the resource ID, path, configuration value, and assertion benchmark are backfilled into the current environment configuration file, and the test data module injected into the automated test script is merged. S8: Identify and execute backend management test scripts first, and capture their runtime output data; S9: Normalize background runtime data into constants that can be referenced by the front end, including switch status classes, configuration parameter classes, resource creation classes, code snippet classes, and display text classes; S10: Write the runtime constants back to the current environment configuration file and re-inject them into the foreground test script; S11: Execute the front-end business test script, and use the backfilled data and runtime constants to verify the page, interface or business status. S12: When it is found that the preconditions are not met during the execution process, the self-healing process of "check - create - verify - backfill - retry" is triggered; S13: Update the test case status, test report, and defect registration information based on the test execution results, data verification results, and write-back records.
[0031] With the above approach, test data is generated by test case preconditions and managed in an isolated environment; the background runtime state can be automatically written back and re-injected into the front-end verification script, thus forming a complete closed loop of "test case parsing - data preparation - self-verification - registration - backfilling - background execution - runtime capture - re-injection - front-end verification - result writing back".
[0032] The following code is an exemplary implementation of the technical solution of this application, used to express the core data structure, processing order and closed-loop control logic; in specific implementation, it can be replaced with Python, Java, JavaScript or other equivalent languages.
[0033] Key Node 1: Precondition Analysis and Data Requirement Tagging.
[0034] Technical Solution: The preconditions, test data, and expected result fields from the test cases are read, and resource type, status requirements, functional characteristics, environment identifiers, account identifiers, and assertion conditions are extracted to form a data requirement object that can be queried and verified by machines. This object serves as the unified input for subsequent Registry queries, API creation, and verification backfilling.
[0035] from dataclasses import dataclass @dataclass class DataRequirement: env: str account: str resource_type: str tags: list[str] assertions: list[str] def build_requirement(case_row: dict, env: str, account: str) ->DataRequirement: source = "\n".join([ case_row.get("precondition", ""), case_row.get("test data", ""), case_row.get("expected result", ""), ]) tags = normalize_tags(source) return DataRequirement( env=env, account = account, resource_type=detect_resource_type(tags), tags=tags + [f"env:{env}", f"account:{account}"], assertions=extract_assertions(source), ) Key Node Two: Environment Isolation Registry Query, Reuse, and Creation.
[0036] Technical solution: Each environment maintains an independent data registry, such as registry_{ENV}.json. Before execution, reusable data is queried in the current environment registry by resource type, tag, and account; if a match is found, status verification is still required; if no match is found or verification fails, the interface is automatically called to create the resource, and the creation result is registered in the current environment registry.
[0037] def resolve_test_data(req: DataRequirement) -> dict: registry = Registry.for_env(req.env) hit = registry.find_reusable( entry_type=req.resource_type, required_tags=req.tags, environment=req.env, ) if hit and verify_resource(hit["data"], req.assertions): return hit["data"] data = create_resource_by_api(req) registry.register( entry_type=req.resource_type, name=build_registry_name(req), tags=req.tags, data=data, environment=req.env, created_by="qa-data-closed-loop", ) return data Key Node 3: Automatic creation of workflows / templates and self-verification after creation.
[0038] Technical Solution: When data requirements are workflows, templates, or backend configurations, the system first creates the workflow, then injects the DSL or configuration parameters, followed by publishing, creating the template, and enabling it. The system then uses APIs or web pages to verify that resource paths, status, and business switches are active. Only data that passes self-verification is allowed to be backfilled and injected with scripts.
[0039] def create_template_data(req: DataRequirement) -> dict: wf_id = create_workflow( user_token=req.account, name=req.tags[0], description="auto data", ) dsl, layout = build_dsl_by_requirement(req) publish_workflow( user_token=req.account, workflow_id=wf_id, dsl=dsl, layout=layout, ) tpl_id = create_template( admin_token=get_admin_token(req.env), source_workflow_id=str(wf_id), orchestrate_data=get_workflow(req.account, wf_id)["orchestrate"], ) enable_template(get_admin_token(req.env), [tpl_id]) path = get_template_path(get_admin_token(req.env), tpl_id) probe = probe_template_page(req.env, path) assert probe["exists"] and probe["enabled"], "template is notready" return {"workflow_id": wf_id, "template_id": tpl_id, "template_path": path} Key Node 4: envdata backfilling and script-side re-injection.
[0040] Technical solution: Environment-specific constants, including template paths, resource IDs, backend configuration values, selectors, and assertion statements, are stored in the current environment configuration file envdata / {ENV}.py. Before execution, the test execution entry point merges env_config.py and envdata / {ENV}.py into a single script, helpers / test_data.py, ensuring that the script reads verified data from the current environment.
[0041] def write_envdata(env: str, values: dict) -> None: lines = render_constants(env=env, values=values) target = Path("test-data / envdata") / f"{env}.py" target.write_text("\n".join(lines), encoding="utf-8") def inject_test_data(test_dir: Path, env: str) -> Path: env_config = Path("test-data / env_config.py").read_text(encoding="utf-8") envdata = Path(f"test-data / envdata / {env}.py").read_text(encoding="utf-8") target = test_dir / "helpers" / "test_data.py" target.write_text(env_config + "\n" + envdata, encoding="utf-8") return target Key Node 5: Background runtime data capture and ADMIN_RT_* constant quantization.
[0042] Technical Solution: During the execution of backend management test cases, switch states, configuration parameters, edited text, code snippets, and newly created resources are uniformly collected. The collected results are converted into ADMIN_RT_* constants through standardized naming and written back to the current environment configuration file for reference by frontend business test cases after reinjection.
[0043] ADMIN_RUNTIME_DATA: dict[str, object] = {} def record_admin_runtime(**values: object) -> None: for raw_key, value in values.items(): ADMIN_RUNTIME_DATA[to_admin_rt_key(raw_key)] = value def to_admin_rt_key(raw_key: str) -> str: normalized = re.sub(r"[^A-Z0-9]+", "_", raw_key.upper()).strip("_") return f"ADMIN_RT_{normalized}" def flush_admin_runtime(env: str) -> None: current = load_envdata_values(env) current.update(ADMIN_RUNTIME_DATA) write_envdata(env, current) Key Node Six: The phased arrangement of the back-end and front-end stages.
[0044] Technical Solution: The test executor splits backend management test cases and frontend business test cases according to their dependencies. The backend phase is executed first to complete runtime data capture and write-back; then, test data is re-injected, and the frontend phase is executed, thus ensuring that the frontend verification uses the data generated by the same backend execution.
[0045] def run_closed_loop(test_plan: list[TestCase], env: str) -> None: admin_cases, front_cases = split_by_stage(test_plan) run_pytest(admin_cases) flush_admin_runtime(env) inject_test_data(front_cases.root, env) run_pytest(front_cases) write_case_results(report="results_raw.json") Key Node 7: Precondition Drift Detection and Self-Healing Retry.
[0046] Technical solution: Data status can be verified both before and during script execution. When a resource does not exist, a template is removed, a switch is ineffective, or the assertion baseline does not match, the system will mark the corresponding registration item as invalid, recreate and verify the data, and refill and retry the target test case after successful verification.
[0047] def ensure_requirement(req: DataRequirement, retries: int = 2) ->dict: last_error = None for _ in range(retries + 1): data = resolve_test_data(req) try: if verify_resource(data, req.assertions): return data except Exception as exc: last_error = exc mark_registry_entry_stale(req.env, data) raise DataNotReadyError(req, last_error) The aforementioned key nodes work together to ensure that after test data enters the system from the test case semantics, it can sequentially complete tagging, reuse or creation within the environment, self-verification, registration and logging, envdata backfilling, background runtime capture, re-injection, and foreground verification. This closed-loop control logic is not only used for initial execution but also for regression testing, environment switching, data migration repair, and rerunning of failed test cases. Example 1
[0048] This embodiment provides a method for closed-loop generation and runtime write-back and re-injection of test data, characterized by the following steps: Step S1: Obtain the test case file, parse the precondition field, test data field, and expected result field in the test case file to obtain the parsing result, and convert the parsing result into a preset format data requirement tag; the preset format data requirement tag includes at least resource type, status requirement, functional characteristics, environment identifier, account identifier, and verification condition; Step S2: Read the current test environment identifier, access the environment isolation data registry corresponding to the current test environment identifier, and use the set fields in the data requirement tag as matching conditions to query whether there is test data that matches all the matching conditions and has a valid registration status. If it exists, perform real-time status detection on the queried test data to confirm that the test data is available in the current target system and meets the status requirements in the data requirement tag. If the real-time status detection confirms that it is available, the queried test data is used as reused test data. If there is no test data with a valid registration status, or if the real-time status detection confirms that it is unavailable, call the business system interface or the backend management interface to create test data that meets the data requirement tag as new test data. Step S3: Perform availability verification on the reused test data or the newly created test data. After the verification is passed, backfill the resource identifier, path information, configuration parameters and assertion benchmark of the test data into the current environment configuration file, record the log information of the backfill operation, the log information includes at least the backfill time, operation account, backfill data item identifier and its value, and dynamically generate a test data module file containing the backfilled test data. Inject the test data module file into the reference path of the automated test script for reference by the backend management test script and the frontend business test script. Step S4: Identify and prioritize the execution of the backend management test script to obtain the first test execution result, capture the runtime data generated by the backend management test script during execution, and normalize the runtime data into runtime constants that can be referenced by the frontend; Step S5: Write the runtime constants back to the current environment configuration file, record the log information of the write-back operation, the log information includes at least the write-back time, operation account, write-back data item identifier and its value, and regenerate the test data module file containing the runtime constants. Inject the regenerated test data module file into the reference path of the front-end business class test script to replace the test data previously referenced by the front-end business class test script. Step S6: Execute the front-end business class test script to obtain the second test execution result, and make the front-end business class test script refer to the backfilled test data and the runtime constants to perform page verification, interface verification or business status verification. Step S7: During the availability verification process of step S3, or during the execution of the test scripts of steps S4 to S6, if it is detected that the test data does not meet the status requirements or verification conditions in the data requirement tag, it is determined that the preconditions are not met and the self-healing process is triggered. The self-healing process includes: re-executing steps S1 to S3 to re-parse the test case fields, rebuild and verify the test data, and retrying the current test case after the verification is passed.
[0049] In this embodiment, preferably, in step S1, the data requirement tag in the preset format is a structured data object containing the following fixed fields: The resource type field is used to identify the category of the test data required; The status requirement field is used to identify the status that the required test data should be in; The functional characteristic field is used to identify the functional attributes of the test data to be tested. The environment identifier field is used to identify the test environment to which the required test data belongs; The account identifier field is used to identify the operating account to which the required test data belongs; The validation criteria field identifies the assertion rules used when performing usability validation on the test data. In step S1, converting the parsing result into a data requirement tag in a preset format specifically includes: Keywords are extracted from the precondition field, test data field, and expected result field. Resource types, status requirements, and functional characteristics are identified through regular expression matching. Current environment identifier and current account identifier are added as mandatory tags.
[0050] In this embodiment, preferably, the environment isolation data registry is maintained independently for each test environment, and each registration record includes at least: resource identifier, resource type, tag list, environment, account, creation time, source test case identifier, and registration status; the registration status is either valid or invalid. When querying whether test data exists that matches all matching conditions and has a valid registration status, it is necessary to match the resource type, tag list, environment, and account simultaneously, and only return records with a valid registration status; In step S2, the "real-time status detection" includes at least one of the following methods: Verify the existence of the resource and whether its status is effective by calling the API. By probing the resource access path on the page, we can confirm the page's accessibility and whether key elements are displayed. Verify that the configuration switch status is consistent with the expected settings.
[0051] In this embodiment, preferably, the availability verification in step S3 includes at least one of the following methods: Verify the existence of the resource and whether its status is effective by calling the API. By probing the resource access path on the page, we can confirm the page's accessibility and whether key elements are displayed. Verify that the configuration switch status is consistent with expectations; Verify whether the number of records has reached the preset threshold; In step S3, the dynamic generation of the test data module file containing the backfilled test data specifically includes: The key-value pairs in the current environment configuration file are converted into constant definition statements in a programming language to generate an independent test data module file. The test data module file provides an access interface for the test data in a constant manner.
[0052] In this embodiment, preferably, the runtime data in step S4 includes at least one of the following types: switch status data, configuration parameter data, newly created resource identifier data, code snippet data, and display text data; The standardization of runtime constants that can be referenced by the front end specifically involves: converting the original name of the runtime data into a constant identifier with a unified naming format, wherein the unified naming format is to replace non-alphanumeric characters in the original name with underscores and convert them to uppercase, and to record the mapping relationship between the constant identifier and the original data. In step S4, capturing the runtime data generated during the execution of the background management test script is achieved in the following way: In the execution context of the backend management test script, a data collection point is preset. When the execution reaches the data collection point, the variable values, interface response return data, or page content in the current context are extracted and collected into the runtime data buffer.
[0053] In this embodiment, preferably, before re-executing steps S1 to S3 in the self-healing process, the corresponding records of the test data determined to not meet the preconditions in step S7 are marked as failures in the environmental isolation data registry, and the failure cause and failure time are recorded.
[0054] In this embodiment, preferably, it further includes step S8: updating the execution status of the test case file and generating a test execution report based on the first test execution result of step S4, the second test execution result of step S6, the first verification result generated by the real-time status detection in step S2, the second verification result generated by the availability verification in step S3, the log information of the backfill operation in step S3, and the log information of the write-back operation recorded in step S5; the test execution report includes at least: data source identifier, environment identifier, account identifier, data creation method, first verification result, second verification result, and write-back record.
[0055] Based on the same inventive concept, this application also provides an apparatus corresponding to the method in Embodiment 1, as detailed in Embodiment 2. Example 2
[0056] like Figure 1As shown, this embodiment provides a test data closed-loop generation and runtime write-back and re-injection device, including: The parsing and tagging module is used to obtain test case files, parse the precondition fields, test data fields, and expected result fields in the test case files to obtain parsing results, and convert the parsing results into data requirement tags in a preset format; the preset format data requirement tags include at least resource type, status requirements, functional characteristics, environment identifier, account identifier, and verification conditions; The environment isolation registry management module is used to read the current test environment identifier, access the environment isolation data registry corresponding to the current test environment identifier, and use the set fields in the data requirement tag as matching conditions to query whether there is test data that matches all the matching conditions and has a valid registration status. If it exists, real-time status detection is performed on the queried test data to confirm that the test data is available in the current target system and meets the status requirements in the data requirement tag. If the real-time status detection confirms that it is available, the queried test data is used as reused test data. If there is no test data with a valid registration status, or if the real-time status detection confirms that it is unavailable, the business system interface or the backend management interface is called to create test data that meets the data requirement tag as new test data. The verification and backfilling injection module is used to perform availability verification on the reused test data or the newly created test data. After the verification is successful, the resource identifier, path information, configuration parameters and assertion benchmark of the test data are backfilled into the current environment configuration file. The backfilling operation log information is recorded. The log information includes at least the backfilling time, operation account, backfilled data item identifier and its value. The module also dynamically generates a test data module file containing the backfilled test data and injects the test data module file into the reference path of the automated test script for reference by the backend management test script and the frontend business test script. The background execution and runtime capture module is used to identify and prioritize the execution of background management test scripts to obtain the first test execution result, capture the runtime data generated by the background management test scripts during execution, and normalize the runtime data into runtime constants that can be referenced by the front end. The runtime constant write-back and re-injection module is used to write the runtime constants back to the current environment configuration file, record the log information of the write-back operation, the log information includes at least the write-back time, operation account, write-back data item identifier and its value, and regenerate the test data module file containing the runtime constants. The regenerated test data module file is injected into the reference path of the front-end business class test script to replace the test data previously referenced by the front-end business class test script. The front-end execution module is used to execute the front-end business class test script, obtain the second test execution result, and enable the front-end business class test script to reference the backfilled test data and the runtime constants to perform page verification, interface verification or business status verification. The self-healing module is used to determine that the preconditions are not met and trigger the self-healing process if the test data does not meet the status requirements or verification conditions in the data requirement tags during the availability verification process of the verification and backfilling injection module, or during the execution of the test script from the background execution and runtime capture module to the foreground execution module. The self-healing process includes: re-executing the parsing and tagging module to the verification and backfilling injection module to re-parse the test case fields, rebuild and verify the test data, and retry the current test case after the verification is passed.
[0057] In this embodiment, preferably, in step S1, the data requirement tag in the preset format is a structured data object containing the following fixed fields: The resource type field is used to identify the category of the test data required; The status requirement field is used to identify the status that the required test data should be in; The functional characteristic field is used to identify the functional attributes of the test data to be tested. The environment identifier field is used to identify the test environment to which the required test data belongs; The account identifier field is used to identify the operating account to which the required test data belongs; The validation criteria field identifies the assertion rules used when performing usability validation on the test data. In the parsing and tagging module, the step of converting the parsing results into data requirement tags in a preset format specifically includes: Keywords are extracted from the precondition field, test data field, and expected result field. Resource types, status requirements, and functional characteristics are identified through regular expression matching. Current environment identifier and current account identifier are added as mandatory tags.
[0058] In this embodiment, preferably, the environment isolation data registry is maintained independently for each test environment, and each registration record includes at least: resource identifier, resource type, tag list, environment, account, creation time, source test case identifier, and registration status; the registration status is either valid or invalid. When querying whether test data exists that matches all matching conditions and has a valid registration status, it is necessary to match the resource type, tag list, environment, and account simultaneously, and only return records with a valid registration status; In the environment isolation registry management module, the "real-time status detection" includes at least one of the following methods: Verify the existence of the resource and whether its status is effective by calling the API. By probing the resource access path on the page, we can confirm the page's accessibility and whether key elements are displayed. Verify that the configuration switch status is consistent with the expected settings.
[0059] In this embodiment, preferably, the usability verification in the verification and backfill injection module includes at least one of the following methods: Verify the existence of the resource and whether its status is effective by calling the API. By probing the resource access path on the page, we can confirm the page's accessibility and whether key elements are displayed. Verify that the configuration switch status is consistent with expectations; Verify whether the number of records has reached the preset threshold; In the verification and backfill injection module, the dynamic generation of the test data module file containing the backfilled test data specifically includes: The key-value pairs in the current environment configuration file are converted into constant definition statements in a programming language to generate an independent test data module file. The test data module file provides an access interface for the test data in a constant manner.
[0060] In this embodiment, preferably, the runtime data in the background execution and runtime capture module includes at least one of the following types: switch status data, configuration parameter data, newly created resource identifier data, code snippet data, and display text data; The standardization of runtime constants that can be referenced by the front end specifically involves: converting the original name of the runtime data into a constant identifier with a unified naming format, wherein the unified naming format is to replace non-alphanumeric characters in the original name with underscores and convert them to uppercase, and to record the mapping relationship between the constant identifier and the original data. In the background execution and runtime capture module, the capture of runtime data generated during the execution of the background management class test script is achieved in the following way: In the execution context of the backend management test script, a data collection point is preset. When the execution reaches the data collection point, the variable values, interface response return data, or page content in the current context are extracted and collected into the runtime data buffer.
[0061] In this embodiment, preferably, before re-executing the parsing and tagging module to the verification and backfilling injection module in the self-healing process, the corresponding records of the test data in the environment isolation data registry that are determined to not meet the preconditions in the self-healing module are marked as failures, and the failure reasons and failure times are recorded.
[0062] In this embodiment, preferably, it further includes a test report generation module, used to update the execution status of the test case file and generate a test execution report based on the first test execution result of the background execution and runtime capture module, the second test execution result of the foreground execution module, the first verification result generated by the real-time status detection in the environment isolation registry management module, the second verification result generated by the availability verification in the verification and backfill injection module, the log information of the backfill operation of the verification and backfill injection module, and the log information of the write-back operation recorded by the runtime constant write-back and re-injection module; the test execution report includes at least: data source identifier, environment identifier, account identifier, data creation method, first verification result, second verification result, and write-back record.
[0063] Since the apparatus described in Embodiment 2 of the present invention is an apparatus used to implement the method of Embodiment 1 of the present invention, those skilled in the art can understand the specific structure and variations of the apparatus based on the method described in Embodiment 1 of the present invention, and therefore will not be described again here. All apparatuses used in the method of Embodiment 1 of the present invention fall within the scope of protection of the present invention.
[0064] Based on the same inventive concept, this application provides an electronic device embodiment corresponding to Embodiment 1, as detailed in Embodiment 3. Example 3
[0065] This embodiment provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it can implement any of the implementation methods in Embodiment 1.
[0066] Since the electronic device described in this embodiment is the device used to implement the method in Embodiment 1 of this application, those skilled in the art can understand the specific implementation method and various variations of the electronic device in this embodiment based on the method described in Embodiment 1 of this application. Therefore, how the electronic device implements the method in the embodiment of this application will not be described in detail here. Any device used by those skilled in the art to implement the method in the embodiment of this application falls within the scope of protection of this application.
[0067] Based on the same inventive concept, this application provides a storage medium corresponding to Embodiment 1, as detailed in Embodiment 4. Example 4
[0068] This embodiment provides a computer-readable storage medium storing a computer program thereon. When the computer program is executed by a processor, it can implement any of the implementation methods in Embodiment 1.
[0069] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0070] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0071] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0072] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0073] While specific embodiments of the present invention have been described above, those skilled in the art should understand that the specific embodiments described are merely illustrative and not intended to limit the scope of the present invention. Equivalent modifications and variations made by those skilled in the art in accordance with the spirit of the present invention should be covered within the scope of protection of the claims of the present invention.
Claims
1. A method for closed-loop generation and runtime write-back and re-injection of test data, characterized in that, Includes the following steps: Step S1: Obtain the test case file, parse the precondition field, test data field, and expected result field in the test case file to obtain the parsing result, and convert the parsing result into a preset format data requirement tag; the preset format data requirement tag includes at least resource type, status requirement, functional characteristics, environment identifier, account identifier, and verification condition; Step S2: Read the current test environment identifier, access the environment isolation data registry corresponding to the current test environment identifier, use the set fields in the data requirement tag as matching conditions, and query whether there is test data that matches all the matching conditions and has a valid registration status; if it exists, perform real-time status detection on the queried test data to confirm that the test data is available in the current target system and meets the status requirements in the data requirement tag; If real-time status detection confirms availability, the retrieved test data will be used as reused test data. If there is no valid test data with a registered status, or if the real-time status detection confirms that it is unavailable, then call the business system interface or the backend management interface to create test data that meets the data requirement tags, and use it as the new test data; Step S3: Perform availability verification on the reused test data or the newly created test data. After the verification is passed, backfill the resource identifier, path information, configuration parameters and assertion benchmark of the test data into the current environment configuration file, record the log information of the backfill operation, the log information includes at least the backfill time, operation account, backfill data item identifier and its value, and dynamically generate a test data module file containing the backfilled test data. Inject the test data module file into the reference path of the automated test script for reference by the backend management test script and the frontend business test script. Step S4: Identify and prioritize the execution of the backend management test script to obtain the first test execution result, capture the runtime data generated by the backend management test script during execution, and normalize the runtime data into runtime constants that can be referenced by the frontend; Step S5: Write the runtime constants back to the current environment configuration file, record the log information of the write-back operation, the log information includes at least the write-back time, operation account, write-back data item identifier and its value, and regenerate the test data module file containing the runtime constants. Inject the regenerated test data module file into the reference path of the front-end business class test script to replace the test data previously referenced by the front-end business class test script. Step S6: Execute the front-end business class test script to obtain the second test execution result, and make the front-end business class test script refer to the backfilled test data and the runtime constants to perform page verification, interface verification or business status verification. Step S7: During the availability verification process of step S3, or during the execution of the test scripts of steps S4 to S6, if it is detected that the test data does not meet the status requirements or verification conditions in the data requirement label, it is determined that the preconditions are not met and the self-healing process is triggered. The self-healing process includes: re-executing steps S1 to S3 to re-parse the test case fields, rebuild and verify the test data, and retrying the current test case after successful verification.
2. The method according to claim 1, characterized in that, In step S1, the preset format data requirement tag is a structured data object containing the following fixed fields: The resource type field is used to identify the category of the test data required; The status requirement field is used to identify the status that the required test data should be in; The functional characteristic field is used to identify the functional attributes of the test data to be tested. The environment identifier field is used to identify the test environment to which the required test data belongs; The account identifier field is used to identify the operating account to which the required test data belongs; The validation criteria field identifies the assertion rules used when performing usability validation on the test data. In step S1, converting the parsing result into a data requirement tag in a preset format specifically includes: Keywords are extracted from the precondition field, test data field, and expected result field. Resource types, status requirements, and functional characteristics are identified through regular expression matching. Current environment identifier and current account identifier are added as mandatory tags.
3. The method according to claim 1, characterized in that, The environment isolation data registry is maintained independently for each test environment. Each registration record includes at least: resource identifier, resource type, tag list, environment, account, creation time, source test case identifier, and registration status. The registration status can be either valid or invalid. When querying whether test data exists that matches all matching conditions and has a valid registration status, it is necessary to match the resource type, tag list, environment, and account simultaneously, and only return records with a valid registration status; In step S2, the "real-time status detection" includes at least one of the following methods: Verify the existence of the resource and whether its status is effective by calling the API. By probing the resource access path on the page, we can confirm the page's accessibility and whether key elements are displayed. Verify that the configuration switch status is consistent with the expected settings.
4. The method according to claim 1, characterized in that, The availability verification in step S3 includes at least one of the following methods: Verify the existence of the resource and whether its status is effective by calling the API. By probing the resource access path on the page, we can confirm the page's accessibility and whether key elements are displayed. Verify that the configuration switch status is consistent with expectations; Verify whether the number of records has reached the preset threshold; In step S3, the dynamic generation of the test data module file containing the backfilled test data specifically includes: The key-value pairs in the current environment configuration file are converted into constant definition statements in a programming language to generate an independent test data module file. The test data module file provides an access interface for the test data in a constant manner.
5. The method according to claim 1, characterized in that, The runtime data in step S4 includes at least one of the following types: switch status data, configuration parameter data, newly created resource identifier data, code snippet data, and display text data; The standardization of runtime constants that can be referenced by the front end specifically involves: converting the original name of the runtime data into a constant identifier with a unified naming format, wherein the unified naming format is to replace non-alphanumeric characters in the original name with underscores and convert them to uppercase, and to record the mapping relationship between the constant identifier and the original data. In step S4, capturing the runtime data generated during the execution of the background management test script is achieved in the following way: In the execution context of the backend management test script, a data collection point is preset. When the execution reaches the data collection point, the variable values, interface response return data, or page content in the current context are extracted and collected into the runtime data buffer.
6. The method according to claim 1, characterized in that, In the self-healing process, before re-executing steps S1 to S3, the corresponding records of the test data that were determined to not meet the preconditions in step S7 are marked as failures in the environmental isolation data registry, and the cause and time of failure are recorded.
7. The method according to claim 1, characterized in that, It also includes step S8, updating the execution status of the test case file and generating a test execution report based on the first test execution result of step S4, the second test execution result of step S6, the first verification result generated by the real-time status detection in step S2, the second verification result generated by the availability verification in step S3, the log information of the backfill operation in step S3, and the log information of the write-back operation recorded in step S5; the test execution report includes at least: data source identifier, environment identifier, account identifier, data creation method, first verification result, second verification result, and write-back record.
8. A device for closed-loop generation and runtime write-back and re-injection of test data, characterized in that, include: The parsing and tagging module is used to obtain test case files, parse the precondition fields, test data fields, and expected result fields in the test case files to obtain parsing results, and convert the parsing results into data requirement tags in a preset format; the preset format data requirement tags include at least resource type, status requirements, functional characteristics, environment identifier, account identifier, and verification conditions; The environment isolation registry management module is used to read the current test environment identifier, access the environment isolation data registry corresponding to the current test environment identifier, use the set fields in the data requirement tag as matching conditions, and query whether there is test data that matches all the matching conditions and has a valid registration status; if it exists, real-time status detection is performed on the queried test data to confirm that the test data is available in the current target system and meets the status requirements in the data requirement tag; If real-time status detection confirms availability, the retrieved test data will be used as reused test data. If there is no valid test data with a registered status, or if the real-time status detection confirms that it is unavailable, then call the business system interface or the backend management interface to create test data that meets the data requirement tags, and use it as the new test data; The verification and backfilling injection module is used to perform availability verification on the reused test data or the newly created test data. After the verification is successful, the resource identifier, path information, configuration parameters and assertion benchmark of the test data are backfilled into the current environment configuration file. The backfilling operation log information is recorded. The log information includes at least the backfilling time, operation account, backfilled data item identifier and its value. The module also dynamically generates a test data module file containing the backfilled test data and injects the test data module file into the reference path of the automated test script for reference by the backend management test script and the frontend business test script. The background execution and runtime capture module is used to identify and prioritize the execution of background management test scripts to obtain the first test execution result, capture the runtime data generated by the background management test scripts during execution, and normalize the runtime data into runtime constants that can be referenced by the front end. The runtime constant write-back and re-injection module is used to write the runtime constants back to the current environment configuration file, record the log information of the write-back operation, the log information includes at least the write-back time, operation account, write-back data item identifier and its value, and regenerate the test data module file containing the runtime constants. The regenerated test data module file is injected into the reference path of the front-end business class test script to replace the test data previously referenced by the front-end business class test script. The front-end execution module is used to execute the front-end business class test script, obtain the second test execution result, and enable the front-end business class test script to reference the backfilled test data and the runtime constants to perform page verification, interface verification or business status verification. The self-healing module is used to determine that the preconditions are not met and trigger the self-healing process if the test data does not meet the status requirements or verification conditions in the data requirement tag during the availability verification process of the verification and backfilling injection module, or during the execution of the test script from the background execution and runtime capture module to the foreground execution module. The self-healing process includes: re-executing the parsing and tagging module to the verification and backfilling injection module to re-parse the test case fields, rebuild and verify the test data, and retrying the current test case after successful verification.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1 to 7.
