CN113986766A - Automatic testing method and device - Google Patents

Automatic testing method and device Download PDF

Info

Publication number
CN113986766A
CN113986766A CN202111432389.3A CN202111432389A CN113986766A CN 113986766 A CN113986766 A CN 113986766A CN 202111432389 A CN202111432389 A CN 202111432389A CN 113986766 A CN113986766 A CN 113986766A
Authority
CN
China
Prior art keywords
database
test case
target test
data form
entry function
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111432389.3A
Other languages
Chinese (zh)
Inventor
曾凌子
符敬伟
邓泳笙
江旻
杨杨
张晶
李理
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
WeBank Co Ltd
Original Assignee
WeBank Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by WeBank Co Ltd filed Critical WeBank Co Ltd
Priority to CN202111432389.3A priority Critical patent/CN113986766A/en
Publication of CN113986766A publication Critical patent/CN113986766A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites

Abstract

The invention relates to the field of financial technology (Fintech), and discloses an automatic test method and device, wherein a basic state test case is cut based on a set target test object to obtain a target test case; the basic state test case is obtained by recording an entry function involved in the service request running in the service system; the base state test case comprises database operation records of the entry function in the execution process and database recovery operation records corresponding to the database operation records respectively; sequentially restoring the databases in a reverse order mode according to the execution sequence of the operation records of the databases based on the operation records of the databases and the recovery operation records of the databases to obtain the data form of the target test case before recording; in this data form, the target test case is played back. The method can achieve the effect of quickly generating each automatic test case under the condition of low manufacturing cost.

Description

Automatic testing method and device
Technical Field
The embodiment of the application relates to the field of financial technology (Fintech), in particular to an automatic testing method and device.
Background
With the development of computer technology, more and more technologies (such as big data, cloud computing or block chain) are applied in the financial field, and the traditional financial industry is gradually shifting to the financial technology. For example, in the context of big data technology, banking business systems are constantly undergoing version upgrades. During version upgrade, the test of whether some old functions in the service system are intact can be performed in an automatic mode. For example, in the field of current bank software Testing, multiple rounds of tests such as unit Testing, Integration Testing, System Testing, Acceptance Testing, and the like are required to be performed according to the progress of a project version, and a function code, a function interface, a single subsystem, and a full-link subsystem are respectively used as test objects, and are respectively completed by a developer, a System Integration Testing (SIT) person, and a User Acceptance Testing (UAT) person. Each test node requires each test executor to compile corresponding automatic test cases by using different frames according to the needs of the executor, and the test cost is multiplied. The automatic test is divided into three contents of data preparation, case execution and result verification, and the repeated work is more. Moreover, the general link of banking business is very long, and the related upstream and downstream systems are numerous, which requires that the test executives in each stage need to deeply understand the system logic and data structure when performing the number making, so that high learning and communication costs exist, which makes the number making difficult to increase, and particularly when batch number making is related, the upstream and downstream are more needed to cooperate, and the labor cost is huge; only a single subsystem may be modified slightly, but still the data structures of multiple subsystems upstream and downstream need to be known, so that the required test data can be created.
Therefore, there is a need for an automatic test method with low manufacturing cost and simple automatic test case construction logic.
Disclosure of Invention
The application provides an automatic test method and device, which are used for achieving the effect of quickly constructing an automatic test case under the condition of low manufacturing cost.
In a first aspect, an embodiment of the present application provides an automated testing method, where the method includes: based on a set target test object, cutting the ground state test case to obtain a target test case; the basic state test case is obtained by recording an entry function involved in the period that the service request runs in the service system; the base state test case comprises incoming parameters and return values of the entry function, incoming parameters and return values of all key sub-functions in the entry function, database operation records of the entry function in the execution process and database recovery operation records corresponding to the database operation records respectively; sequentially restoring the databases in a reverse order mode according to the execution sequence of the operation records of the databases based on the operation records of the databases and the recovery operation records of the databases to obtain the data form of the target test case before recording; and playing back the target test case under the data form.
In the scheme, based on the interception and recording of the flow, when the service request relates to a full link subsystem in a service system, each sub-test case meeting various test conditions, namely a target test case, can be easily obtained by cutting the recorded basic state test case by recording the basic state test case corresponding to the service request; meanwhile, in the recording process of the ground state test case, the recorded database operation records are converted into database recovery operation records for recovering the database, so that the database can be quickly recovered to the data form of the target test case before recording when the target test case is played back subsequently. The method can achieve the effect of quickly generating each automatic test case under the condition of low manufacturing cost.
In one possible implementation method, the base state test case is obtained by recording an entry function involved during a service request running in a service system, and the method includes: acquiring an incoming parameter of an entry function for the entry function during the service request running in the service system; when any database operation in the entry function is executed, suspending the database operation, generating a database recovery operation record corresponding to the database operation based on an initial data form of a database before the database operation, and executing the database operation after caching the database operation record and the database recovery operation record corresponding to the database operation record; when any key subfunction in the entry function is executed, acquiring an incoming parameter and a return value of the key subfunction; and after the operation of the entry function is finished, acquiring a return value of the entry function, and backing up an end data form of the database.
In the above scheme, a process of generating a ground state test case is described, which includes intercepting a service request by an AOP technology, so as to obtain some parameters in an execution process of the service request, including an incoming parameter and a return value of an entry function corresponding to the service request, each database operation record of the entry function and each corresponding database recovery operation record, an incoming parameter and a return value of each key sub-function, and an end data form of the service request after execution, where the contents are contents of the ground state test case; based on the ground state test case, the ground state test case can be subsequently cut according to the user-defined requirement, so that the target test case desired by the user can be quickly obtained, and the automatic test of the target test case is realized.
In one possible implementation, the generating a database recovery operation record corresponding to the database operation based on an initial data form of the database before the database operation includes: generating a database query statement corresponding to the database operation based on the database operation, and obtaining an initial data form of the database through the database query statement; and generating database adding operation corresponding to the initial data form based on the initial data form of the database, and taking the database adding operation as a database recovery operation record corresponding to the database operation.
In the above scheme, a generation process of each database recovery operation record is described, including that for each database operation in the service request execution process, the database operation may be suspended based on the AOP technology, that is, the database operation is not immediately executed, but a database query statement corresponding to the database operation is generated, and by executing the database query statement, an initial data form of the database may be obtained, and after the initial data form of the database is taken, a database addition operation corresponding to the initial data form may be generated, where the database addition operation is a database recovery operation record. In the method, in the process of recording the ground state test case, the database recovery operation corresponding to any database operation record is constructed, so that before the target test case is played back subsequently, the database can be easily recovered to the data form before the target test case is recorded on the basis of the database operation record of each group and the corresponding database recovery operation record, and the automatic test of the target test case can be realized.
In one possible implementation of the method, the target test object is the entry function; the cutting of the ground state test case based on the set target test object to obtain the target test case comprises the following steps: taking the incoming parameters of the entry function as test messages in a target test case; taking the return value of the entry function as a message check point in the target test case; taking the incoming parameters and the return values of all key sub-functions which are not in the set range in the entry function as baffle data in the target test case; and taking the data form obtained after the entry function executes each database operation as a data form check point in the target test case.
In the above scheme, how to crop the ground state test case to obtain the target test case when the target test object is the entry function is described. In the mode, the effect that the ground state test case can be repeatedly used after being recorded once is achieved.
In one possible implementation method, the target test object is any key subfunction in the entry function; the cutting of the ground state test case based on the set target test object to obtain the target test case comprises the following steps: taking the incoming parameters of the key subfunction as test messages in a target test case; taking the return value of the key subfunction as a message check point in the target test case; taking the incoming parameters and the return values of each key sub-function called for each external interface in the key sub-functions as baffle data in the target test case; and taking the final data form obtained after the key subfunction is executed as a data form check point in the target test case.
In the above scheme, how to cut the ground state test case to obtain the target test case when the target test object is a certain key subfunction in the entry function is described. In the mode, the effect that the ground state test case can be repeatedly used after being recorded once is achieved.
In a possible implementation method, the database operation records are sequentially stored according to an execution sequence; the sequentially restoring the databases in a reverse order mode according to the execution sequence of the operation records of the databases based on the operation records of the databases and the recovery operation records of the databases to obtain the data form of the target test case before recording comprises the following steps: sequentially acquiring the operation records of each database according to the sequence opposite to the execution sequence; for any database operation record in the database operation records, if the database operation record indicates any one of query operation, deletion operation and update operation to the database, operating the database according to the database recovery operation record corresponding to the database operation record; if the database operation record indicates that the database is subjected to insertion operation, ignoring a database recovery operation record corresponding to the database operation record; and after finishing the processing of the last database operation record in the database operation records, obtaining the data form of the target test case before recording.
In the above scheme, how to obtain the data form of the target test case before recording based on each database operation record and the corresponding database recovery operation record is described. The database operation records are sequentially taken out from the cache according to the sequence opposite to the execution sequence of each database operation, when the taken-out database operation records are judged and determined to be any one type of database query, deletion and update operations, the database recovery operation records corresponding to the database operation records can be executed on the database, and when the taken-out database operation records are judged to be the database insertion operation type, the processing is skipped, so that the database can be quickly and accurately recovered to the data form of the target test case before recording in a reverse backtracking mode, and further, the automatic test on the target test case is realized.
In one possible implementation, the target test case includes a first message return value and a first data form of a database; the playing back the target test case in the recording environment includes: recording a second message return value and a second data form of the database by replaying the target test case; verifying the second message return value based on the first message return value to obtain a first verification result, and verifying the second data form based on the first data form to obtain a second verification result; and if the first check result and the second check result are respectively consistent, determining that the business system is correctly upgraded under the target test object.
In the above scheme, the content of the automated test includes a comparison between a return message and a data form obtained after the execution of each database operation is finished, so that by comparing a message return value of the target test object during recording with a message return value during playback, and comparing a data form of the target test object during recording with a data form during playback, if and only if the two results are the same, it can be determined that the service system has completed correct upgrade under the target test object.
In a second aspect, an embodiment of the present application provides an automated testing apparatus, including: the target test case obtaining unit is used for cutting the ground state test case based on a set target test object to obtain a target test case; the basic state test case is obtained by recording an entry function involved in the period that the service request runs in the service system; the base state test case comprises incoming parameters and return values of the entry function, incoming parameters and return values of all key sub-functions in the entry function, database operation records of the entry function in the execution process and database recovery operation records corresponding to the database operation records respectively; a data form obtaining unit, configured to sequentially restore the databases in a reverse order manner according to the execution order of the operation records of the databases based on the operation records of the databases and the recovery operation records of the databases, so as to obtain a data form of the target test case before recording; and the test case playback unit is used for playing back the target test case under the data form.
In a third aspect, an embodiment of the present application provides a computing device, including:
a memory for storing program instructions;
and the processor is used for calling the program instructions stored in the memory and executing the implementation method of the first aspect according to the obtained program.
In a fourth aspect, the present application provides a computer-readable storage medium storing computer-executable instructions for causing a computer to perform the method according to any one of the first aspects.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
Fig. 1 is a schematic diagram of an automated testing method according to an embodiment of the present disclosure;
fig. 2 is a schematic diagram of an automated testing apparatus according to an embodiment of the present disclosure;
fig. 3 is a schematic diagram of a computing device according to an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application clearer, the present application will be described in further detail with reference to the accompanying drawings, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
At present, along with the vigorous development of banking business and the continuous updating of computer technology, the business system of the bank is continuously updated and updated. For the function which is not changed before and after the version upgrade, whether the function can be not influenced can be verified in an automatic test mode.
At present, along with the progress of a project version, a great number of nodes to be tested are required, for example, multiple rounds of tests including unit tests, integration tests, system tests, acceptance tests and the like are required, and the tests are respectively completed by a developer, SIT personnel and UAT personnel by taking a function code, a functional interface, a single subsystem and a full-link subsystem as test objects. Therefore, before each node is tested, each test executor is required to write corresponding automatic test cases by using different frameworks according to own needs. In addition, the banking business generally has a long link, and the related upstream and downstream systems are various, which requires the test executors at each stage to deeply understand the system logic and data structure during the modeling, so that high learning and communication costs exist, and the difficulty of the modeling becomes large.
In view of the above technical problems, embodiments of the present application provide an automated testing method, which can achieve the goals of reducing manufacturing cost and simplifying the construction logic of automated testing cases of each testing node.
Fig. 1 is a schematic diagram of an automated testing method provided in an embodiment of the present application, where the method includes the following steps:
step 101, cutting a basic state test case based on a set target test object to obtain a target test case; the basic state test case is obtained by recording an entry function involved in the period that the service request runs in the service system; the base state test case comprises the incoming parameters and the return values of the entry function, the incoming parameters and the return values of all key sub-functions in the entry function, all database operation records of the entry function in the execution process and all database recovery operation records corresponding to all the database operation records respectively.
In some implementations of the present application, the ground state test case is obtained by recording an entry function involved during a service request running in a service system, and includes: acquiring an incoming parameter of an entry function for the entry function during the service request running in the service system; when any database operation in the entry function is executed, suspending the database operation, generating a database recovery operation record corresponding to the database operation based on an initial data form of a database before the database operation, and executing the database operation after caching the database operation record and the database recovery operation record corresponding to the database operation record; when any key subfunction in the entry function is executed, acquiring an incoming parameter and a return value of the key subfunction; and after the operation of the entry function is finished, acquiring a return value of the entry function, and backing up an end data form of the database.
In some implementations of the present application, the generating a database recovery operation record corresponding to the database operation based on an initial data form of the database before the database operation includes: generating a database query statement corresponding to the database operation based on the database operation, and obtaining an initial data form of the database through the database query statement; and generating database adding operation corresponding to the initial data form based on the initial data form of the database, and taking the database adding operation as a database recovery operation record corresponding to the database operation.
Currently, the automated testing case of the bank software includes both persistent data (the persistent data indicates the form of data stored in the database) and messages. In other words, for an old function to be tested, the recorded message return value and the database record can be used as a reference for verifying whether the old function is still intact after the service system is upgraded by recording the message return value when the old function is operated before the service system version is upgraded and the corresponding database record after the operation.
Aop (aspect organized programming), in the software industry, means a technique for implementing unified maintenance of program functions by means of pre-compilation and dynamic proxy during operation, by means of profile-Oriented programming. The AOP is a continuation of OOP (Object Oriented Programming), is a hot spot in software development, is also an important content in Spring framework, and is a derived normal form of functional Programming. By utilizing the AOP, all parts of the business logic can be isolated, so that the coupling degree between all parts of the business logic is reduced, the reusability of a program is improved, and the development efficiency is improved. The AOP performs dynamic enhancement notification on any method class in a Java byte code enhancement mode, wherein the dynamic enhancement notification comprises a front notification, a rear notification, a back notification, an exception throwing notification, a surrounding notification and the like. By realizing the enhanced logic of each function, any function method can be intercepted, so that the access parameter, the return value and the context are obtained; the hijacking request can also be implemented by inserting own operation before the request is processed, for example, reading the database record related to the request before the request occurs before executing the database request, and then executing the database operation.
In software programming, for example, for bank software programming, when a transaction function is to be implemented, a plurality of subsystems may be involved, for example, for a car credit transaction initiated by a user, one involved subsystem may be an anti-fraud system; furthermore, in the anti-fraud system, further next-level subsystems such as account opening anti-fraud, review anti-fraud, borrow anti-fraud and loan anti-fraud are involved. Each subsystem is specifically composed of an individual function, which includes an entry function for implementing the subsystem, and key sub-functions of the entry function, such as a function called by a database and a function called by an external system.
The test object during unit test is a function code, the test object during integrated test is a function interface, the test object during system test is a single subsystem, and the test object during acceptance test is a full-link subsystem, so that if a certain transaction function in software is determined whether to cut the transaction function and how to cut the transaction function by recording the flow of the transaction function before version upgrade, the automatic test case of all the custom types of test objects under the transaction function can be manufactured based on the same test case, and the effects of one-time recording and repeated use of the automatic test case are achieved.
For example, in the case where the test object is a functional interface, since a subsystem interface is a functional method, the set of test cases of all sub-functions passed by the functional method is the test case of the functional interface.
Furthermore, for the case that the test object is a subsystem (including a single subsystem and a full link subsystem), one transaction is realized by a plurality of subsystem interfaces, and the same field exists in the messages of different subsystem interfaces under the same transaction, for example, the field of the service serial number is always kept unchanged in the message of each subsystem interface, so that a test case of a complete transaction is a set of test cases of all the interfaces for realizing the transaction.
Based on the AOP technology, the embodiment of the application can realize the recording of the test messages and the return values of all test function interfaces and the persistent data in the database before the interactive execution of the database each time, and the recording is precipitated as a basic state test case for the full link subsystem related to the transaction request, so that the recording can be repeatedly used, and the work of repeated manufacturing numbers generated by repeated tests caused by all test roles, all test stages and no matter the size is changed is avoided. The following description of the scheme is given by taking a single function (set as function a) as an entry function and taking the recording of the base state test case as an example:
step 1: requesting the execution thread to reach the function A to be tested.
Step 2: the incoming parameters of function a are recorded in the @ beam notification of function a.
And step 3: when a function is executed to a function B executing a Structured Query Language (SQL) statement of a database, firstly, recording the SQL statement to be executed in an @ BEFORE notification of the function B, and suspending; and then, the SQL sentence to be executed is analyzed by reflecting the database connection of the program, and whether the SQL sentence to be executed is a single table SQL sentence or a multi-table SQL sentence is judged.
Case 1: for a query (select) statement, a delete (delete) statement, and an update (update) statement that are resolved into a single table, the following steps may be included:
step 3.1.1: and analyzing the table related to the SQL statement to be executed and the query condition in a mode of pattern matching, and then combining select to form a new query statement. For example:
the SQL statement to be executed is: update table1 set column1 ═ a 'where column2 ═ b';
then, the table name obtained by the analysis is: table 1; the query conditions are as follows: where column2 ═ b'.
Thus, the resulting new query statement is:
select*from table1 where column2=’b’。
step 3.1.2: and executing a new query statement through the system database connection pool to obtain the current data record of the service database. For example, after a database query is performed according to a new query statement, the data records shown in table1 below are obtained, that is, the data records recorded in table1 are the current data records of the database.
Column1 Column2 Column3
A1 B1 C1
A2 B2 C2
TABLE1 database records
Step 3.1.3: and converting the obtained database record into an insert statement. Wherein the insert statement is used for data preparation in an automated test. For example, based on the data records listed in table1, the following insert statements can be converted:
insert into table1(Column1,Column2,Column3)values(‘A1’,’B1’,’C1’),(‘A2’,’B2’,’C2’)
case 2: for select statement, delete statement, update statement parsed into multiple tables, the following steps can be included:
step 3.2.1: firstly, uniformly converting the table-connected SQL statement into a select format through pattern matching, and analyzing a plurality of table names related in the SQL statement.
Step 3.2.2: and executing the select statement through the connection of the system database to obtain a result set of the current database record, wherein the result set comprises fields and values.
Step 3.2.3: and inquiring a plurality of tables and fields thereof related to the table-connected SQL statement, wherein the name of each table field is unique, so that the table to which each field belongs in the result set can be judged. In the multi-table lookup, since the field name is not repeated for each field, it is possible to determine to which table the field of the database record to be looked up belongs.
Step 3.2.4: and generating corresponding insert statements for the multiple tables respectively. insert statements are used for data preparation in automated testing.
It is noted that the processing logic in this step (i.e., step 3) is to obtain the database record first, then convert it into an insert statement, and finally output the insert statement and the original SQL statement to be executed by the subsystem. In addition, the output result of this step is not used in the following steps 4-6, but used in the case cutting module of the subsequent flow for generating the artificial number SQL statement.
And 4, step 4: requesting the execution thread to reach a sub-function C of function a, recording the incoming parameters of function C in the @ beam notification of function C, and recording the RETURN value of function C in the @ RETURN notification of function C.
And 5: and recording the RETURN value of the function A in the @ RETURN notice of the function A to be tested.
Step 6: after the function A returns, according to the table of the function passing through, SQL is converted into a select statement in the same way as in step 3, and database records are backed up; the backed up database record (i.e. the end data form) is used for the result verification of the automatic test in the subsequent process.
The above describes how to obtain the ground state test case with only function a as the entry function. The base state test case comprises incoming parameters and return values of the function A, incoming parameters and return values of the sub-function C, SQL (structured query language) statements executed by each database and insert statements corresponding to the SQL statements executed by each database, wherein each insert statement is a database recovery operation record for recovering the database.
In some implementations of the present application, the target test object is the entry function; the cutting of the ground state test case based on the set target test object to obtain the target test case comprises the following steps: taking the incoming parameters of the entry function as test messages in a target test case; taking the return value of the entry function as a message check point in the target test case; taking the incoming parameters and the return values of all key sub-functions which are not in the set range in the entry function as baffle data in the target test case; and taking the data form obtained after the entry function executes each database operation as a data form check point in the target test case.
In some implementations of the present application, the target test object is any key subfunction in the entry function; the cutting of the ground state test case based on the set target test object to obtain the target test case comprises the following steps: taking the incoming parameters of the key subfunction as test messages in a target test case; taking the return value of the key subfunction as a message check point in the target test case; taking the incoming parameters and the return values of each key sub-function called for each external interface in the key sub-functions as baffle data in the target test case; and taking the final data form obtained after the key subfunction is executed as a data form check point in the target test case.
For the above step 101, during the transaction joint debugging process, the incoming parameters and return values of the subsystems, interfaces and key function methods involved in the transaction can be recorded through the capability of flow recording, and the data records in the database involved in the transaction are deposited as the base state test cases before each interaction with the database.
The case cutting module realizes that a specific function method is singly tested based on the deposited ground state test case according to the requirement of a test stage, a single interface is tested, a plurality of subsystems and a plurality of interfaces are tested, different test cut-in functions are selected, required input parameters are cut out to be used as test messages, return values are used as verification objects, and each database operation is used as a manufacturing basis to form a sub-case, namely a target test case. Through the capability, the deposited ground state test case can be used as a universal automatic test scheme and is simultaneously used for developing single test, SIT system test and UAT acceptance test, the automatic case is not required to be repeatedly written by adopting different test frames in each test stage, and the effect that one automatic case covers the whole test process is achieved.
It should be noted that, in the embodiment of the present application, an entry function to be tested is referred to as a main entry, and a key function method that is passed through during the running process of the entry function is referred to as a sub-call, where the sub-call supports customization, for example, a call function that defines an external interface in the embodiment of the present application belongs to a key function. The main entry and the sub-called entry, return value and database operation flow are recorded through flow recording.
Taking the cutting of the automated test cases required for the unit test and the interface test as an example, the following describes the constituent factors of the automated test cases (i.e. target test cases) required for the unit test and the interface test, including:
1. and intercepting the entry of the function and returning the value.
2. And intercepting the entry parameter of the function code block for the sub-call of the external system interface and returning the value.
3. And intercepting SQL statements executed by the database in the function code block and corresponding insert statements recorded in the database before the SQL statements are executed.
And (3) by the steps, taking the incoming parameters of the entry function as test messages, taking the return value of the entry function as a message check point, taking the incoming parameters and the return value of the external system interface sub-call function as baffle data, and taking the database operations and the derived database recovery operation records as the data creation basis to assemble a target test case for unit test and interface test.
For the acceptance test of multiple systems and multiple interfaces, the flow of each subsystem interface to be tested is respectively intercepted according to the flow intercepting mode of a single interface, and for the subsystems not to be tested, only the parameter return value needs to be recorded for baffle service.
For example, the generation processes of two target test cases are discussed separately below:
case 1: for a single interface function, the clipped traffic is assembled into a test case by:
1. and taking the entry parameter of the main entry function as a test message.
2. And taking the return value of the main entry function as a check point.
3. SQL sentences stored in the database operation flow and insert sentences constructed by database records before operation are used as the data of the manufacturer bottom layer.
4. And taking the entry parameter and the return value called by the external interface child as a baffle data source.
5. And taking the database form backup after the test interface is executed as a check point.
Case 2: for a transaction link involving multiple interfaces and multiple subsystems, assembling the tailored traffic into a test case by:
1. and taking the entry function of the whole transaction link as a test message.
2. And taking the return value of the entry function of the whole transaction link as a check point.
3. SQL sentences stored in the database operation flow of the tested multi-interface subsystem and insert sentences constructed by the database records before operation are used as the manufacturer underlying data.
4. And (4) taking the sub-call entry parameter and the return value of the interface and the subsystem which are not in the test range as a baffle data source.
5. And taking the database form backup after the test interface is executed as a check point.
And 102, sequentially restoring the databases in a reverse order mode according to the execution sequence of the operation records of the databases based on the operation records of the databases and the recovery operation records of the databases to obtain the data form of the target test case before recording.
In some implementations of the present application, the database operation records are stored sequentially according to an execution order; the sequentially restoring the databases in a reverse order mode according to the execution sequence of the operation records of the databases based on the operation records of the databases and the recovery operation records of the databases to obtain the data form of the target test case before recording comprises the following steps: sequentially acquiring the operation records of each database according to the sequence opposite to the execution sequence; for any database operation record in the database operation records, if the database operation record indicates any one of query operation, deletion operation and update operation to the database, operating the database according to the database recovery operation record corresponding to the database operation record; if the database operation record indicates that the database is subjected to insertion operation, ignoring a database recovery operation record corresponding to the database operation record; and after finishing the processing of the last database operation record in the database operation records, obtaining the data form of the target test case before recording.
In the process of automatic testing, for a test object, the initial database form before case recording and before case playback is required to be consistent, so that the message return value during case playback and the database record after the execution of each database operation can be verified based on the message return value during case recording and the database record after the execution of each database operation; otherwise, if the case recording is inconsistent with the database starting point of the case playback, there is no comparability, and it is naturally impossible to verify whether the test object is intact before and after the system upgrade.
Based on this, in the embodiment of the present application, in the process of recording the ground state test case, the database operation flow is recorded, that is, each database operation record and the database recovery operation record corresponding to each database operation record one to one, based on the foregoing example, that is, the database executes the SQL statement and the insert statement corresponding to the SQL statement; in order to realize the recovery of the database state, in the embodiment of the present application, taking a single table query as an example, the following manner may be adopted to recover the database state:
step 1: database records are emptied.
Step 2: and acquiring the database interaction times of the cases, wherein N is assumed. Set I ═ N.
And step 3: and acquiring the I-th SQL statement and the corresponding insert statement from the flow according to the reverse order.
And 4, step 4: if the SQL statement is a select statement, an update statement or a delete statement, the delete statement is converted according to the query condition, the data is deleted firstly, and then an insert statement of the backup data is executed; if it is an insert statement, skip no processing.
And 5: if the SQL statement is the first item, ending; otherwise, returning to execute the step 2.
For a multi-table query statement, the multi-table query statement can be converted into a delete statement according to the backed-up multi-table insert statement and the field and the value, the data is deleted firstly, and then the insert statement is executed.
By the reverse backtracking mode, database records required by case execution can be automatically generated according to the flow, the problem that the number making logic which consumes the longest time in the process of repeatedly compiling the automatic cases is avoided, and a large amount of work is saved.
And 103, playing back the target test case in the data form.
Based on the step 102, before playing back the target test case, the database can be restored to the database form before recording the target test case; and after the database recovers the data form before the target test case is recorded, the target test case can be played back. In the process of replaying the target test case, whether a baffle function needs to be set is determined according to the attribute of the target test case; if the baffle function needs to be set, the baffle function is set firstly, and then the message sending step is executed, otherwise, the message sending step is directly executed. Wherein:
in the embodiment of the present application, the baffle (mock) function can also be implemented based on the AOP technology. Whereas a transaction involves many subsystems and interfaces, the scope of the current test indicated by the target test case may be only one of the interfaces, or even only one of the methods. Therefore, the embodiment of the application can perform mock on the subsystem and the interface request which are out of the test range. The baffle setting step is as follows:
step 1: and extracting the entry and return values of all interface sub-calls outside the test range from the case cutting flow.
Step 2: and distributing the external sub-call parameter return value to the agent of each subsystem through the interface, performing AOP (automatic optical plane processing) enhancement on the sub-call method, analyzing the parameter object through Java reflection, performing comparison and matching with the recorded flow parameter, taking the return value with the most similar flow as a baffle return message, and not really calling the external interface.
And step 3: and after sending the test message to the entry method, when entering an external interface calling method, performing mock return on the request through the matching rule realized in the last step of AOP enhancement.
In the embodiment of the present application, in the message sending step involved in case playback, because the interface and the specified function are tested at the same time, in the embodiment of the present application, unlike the case where the corresponding protocol messages such as HTTP and RMB are sent through the interface protocol for testing, the embodiment of the present application adopts an agent manner to implement an HTTP interface, receive the Method and the message to be tested, and then call the interface or the Method to be tested in a manner of Java's Method reflecting Invoke, so as to obtain the return value of the interface Method.
In some implementations of the present application, the target test case includes a first message return value and a first data modality of a database; the playing back the target test case in the recording environment includes: recording a second message return value and a second data form of the database by replaying the target test case; verifying the second message return value based on the first message return value to obtain a first verification result, and verifying the second data form based on the first data form to obtain a second verification result; and if the first check result and the second check result are respectively consistent, determining that the business system is correctly upgraded under the target test object.
Based on the above example, after the playback operation on the target test case is finished, the message return value can be obtained, and the data form after playback can be obtained according to the query statement corresponding to each database operation related to the target test case. The correctness of the target test object after the service system is upgraded is judged by the message return value when the target test case is recorded and the data form backed up after the recording is finished, and the method comprises the following steps:
case 1: when the message return value during playback is consistent with the message return value during recording, and the data form during playback is consistent with the data form during recording, the target test object is confirmed to be correctly upgraded;
case 2: and when the message return value during playback is inconsistent with the message return value during recording, and/or the data form during playback is inconsistent with the data form during recording, determining that the target test object has an error in the upgrading process.
Based on the same concept, an automatic testing apparatus is provided in the embodiments of the present application, and as shown in fig. 2, the automatic testing apparatus is a schematic diagram of the automatic testing apparatus provided in the embodiments of the present application, and the automatic testing apparatus includes a target test case obtaining unit 201, a data form obtaining unit 202, and a test case playback unit 203;
a target test case obtaining unit 201, configured to cut the ground state test case based on a set target test object to obtain a target test case; the basic state test case is obtained by recording an entry function involved in the period that the service request runs in the service system; the base state test case comprises incoming parameters and return values of the entry function, incoming parameters and return values of all key sub-functions in the entry function, database operation records of the entry function in the execution process and database recovery operation records corresponding to the database operation records respectively;
a data form obtaining unit 202, configured to sequentially restore the databases in a reverse order according to the execution order of the operation records of the databases based on the operation records of the databases and the recovery operation records of the databases, so as to obtain a data form of the target test case before recording;
a test case playback unit 203, configured to play back the target test case in the data form.
Further, for the apparatus, a ground state test case obtaining unit 204 is further included; a ground state test case obtaining unit 204 for: acquiring an incoming parameter of an entry function for the entry function during the service request running in the service system; when any database operation in the entry function is executed, suspending the database operation, generating a database recovery operation record corresponding to the database operation based on an initial data form of a database before the database operation, and executing the database operation after caching the database operation record and the database recovery operation record corresponding to the database operation record; when any key subfunction in the entry function is executed, acquiring an incoming parameter and a return value of the key subfunction; and after the operation of the entry function is finished, acquiring a return value of the entry function, and backing up an end data form of the database.
Further, for the apparatus, the ground state test case obtaining unit 204 is specifically configured to: generating a database query statement corresponding to the database operation based on the database operation, and obtaining an initial data form of the database through the database query statement; and generating database adding operation corresponding to the initial data form based on the initial data form of the database, and taking the database adding operation as a database recovery operation record corresponding to the database operation.
Further, for the apparatus, the target test object is the entry function; the target test case obtaining unit 201 is specifically configured to: taking the incoming parameters of the entry function as test messages in a target test case; taking the return value of the entry function as a message check point in the target test case; taking the incoming parameters and the return values of all key sub-functions which are not in the set range in the entry function as baffle data in the target test case; and taking the data form obtained after the entry function executes each database operation as a data form check point in the target test case.
Further, for the apparatus, the target test object is any key subfunction in the entry function; the target test case obtaining unit 201 is specifically configured to: taking the incoming parameters of the key subfunction as test messages in a target test case; taking the return value of the key subfunction as a message check point in the target test case; taking the incoming parameters and the return values of each key sub-function called for each external interface in the key sub-functions as baffle data in the target test case; and taking the final data form obtained after the key subfunction is executed as a data form check point in the target test case.
Further, for the device, the database operation records are sequentially stored according to the execution sequence; the data form obtaining unit 202 is specifically configured to: sequentially acquiring the operation records of each database according to the sequence opposite to the execution sequence; for any database operation record in the database operation records, if the database operation record indicates any one of query operation, deletion operation and update operation to the database, operating the database according to the database recovery operation record corresponding to the database operation record; if the database operation record indicates that the database is subjected to insertion operation, ignoring a database recovery operation record corresponding to the database operation record; and after finishing the processing of the last database operation record in the database operation records, obtaining the data form of the target test case before recording.
Further, for the device, the target test case comprises a first message return value and a first data form of a database; testing the playback unit therein, in particular for: recording a second message return value and a second data form of the database by replaying the target test case; verifying the second message return value based on the first message return value to obtain a first verification result, and verifying the second data form based on the first data form to obtain a second verification result; and if the first check result and the second check result are respectively consistent, determining that the business system is correctly upgraded under the target test object.
The embodiment of the present application further provides a computing device, which may specifically be a desktop computer, a portable computer, a smart phone, a tablet computer, a Personal Digital Assistant (PDA), and the like. The computing device may include a Central Processing Unit (CPU), memory, input/output devices, etc., the input devices may include a keyboard, mouse, touch screen, etc., and the output devices may include a Display device, such as a Liquid Crystal Display (LCD), a Cathode Ray Tube (CRT), etc.
Memory, which may include Read Only Memory (ROM) and Random Access Memory (RAM), provides the processor with program instructions and data stored in the memory. In an embodiment of the present application, the memory may be configured to store program instructions for an automated testing method;
and the processor is used for calling the program instructions stored in the memory and executing the automatic test method according to the obtained program.
As shown in fig. 3, a schematic diagram of a computing device provided in an embodiment of the present application includes:
a processor 301, a memory 302, a transceiver 303, a bus interface 304; the processor 301, the memory 302 and the transceiver 303 are connected through a bus 305;
the processor 301 is configured to read the program in the memory 302 and execute the above automatic testing method;
the processor 301 may be a Central Processing Unit (CPU), a Network Processor (NP), or a combination of a CPU and an NP. But also a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a Programmable Logic Device (PLD), or a combination thereof. The PLD may be a Complex Programmable Logic Device (CPLD), a field-programmable gate array (FPGA), a General Array Logic (GAL), or any combination thereof.
The memory 302 is used for storing one or more executable programs, and may store data used by the processor 301 in performing operations.
In particular, the program may include program code including computer operating instructions. The memory 302 may include a volatile memory (volatile memory), such as a random-access memory (RAM); the memory 302 may also include a non-volatile memory (non-volatile memory), such as a flash memory (flash memory), a Hard Disk Drive (HDD) or a solid-state drive (SSD); the memory 302 may also comprise a combination of memories of the kind described above.
The memory 302 stores the following elements, executable modules or data structures, or a subset thereof, or an expanded set thereof:
and (3) operating instructions: including various operational instructions for performing various operations.
Operating the system: including various system programs for implementing various basic services and for handling hardware-based tasks.
The bus 305 may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown in FIG. 3, but this does not mean only one bus or one type of bus.
The bus interface 304 may be a wired communication access port, a wireless bus interface, or a combination thereof, wherein the wired bus interface may be, for example, an ethernet interface. The ethernet interface may be an optical interface, an electrical interface, or a combination thereof. The wireless bus interface may be a WLAN interface.
The embodiment of the application also provides a computer-readable storage medium, and the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used for enabling a computer to execute the automatic testing method.
It will be apparent to those skilled in the art that embodiments of the present application may be provided as a method, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may 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, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may 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, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While the preferred embodiments of the present application have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all alterations and modifications as fall within the scope of the application.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (10)

1. An automated testing method, comprising:
based on a set target test object, cutting the ground state test case to obtain a target test case; the basic state test case is obtained by recording an entry function involved in the period that the service request runs in the service system; the base state test case comprises incoming parameters and return values of the entry function, incoming parameters and return values of all key sub-functions in the entry function, database operation records of the entry function in the execution process and database recovery operation records corresponding to the database operation records respectively;
sequentially restoring the databases in a reverse order mode according to the execution sequence of the operation records of the databases based on the operation records of the databases and the recovery operation records of the databases to obtain the data form of the target test case before recording;
and playing back the target test case under the data form.
2. The method of claim 1,
the ground state test case is obtained by recording an entry function involved in a service request running in a service system, and comprises the following steps:
acquiring an incoming parameter of an entry function for the entry function during the service request running in the service system;
when any database operation in the entry function is executed, suspending the database operation, generating a database recovery operation record corresponding to the database operation based on an initial data form of a database before the database operation, and executing the database operation after caching the database operation record and the database recovery operation record corresponding to the database operation record;
when any key subfunction in the entry function is executed, acquiring an incoming parameter and a return value of the key subfunction;
and after the operation of the entry function is finished, acquiring a return value of the entry function, and backing up an end data form of the database.
3. The method of claim 2,
generating a database recovery operation record corresponding to the database operation based on the initial data form of the database before the database operation, including:
generating a database query statement corresponding to the database operation based on the database operation, and obtaining an initial data form of the database through the database query statement;
and generating database adding operation corresponding to the initial data form based on the initial data form of the database, and taking the database adding operation as a database recovery operation record corresponding to the database operation.
4. The method of claim 1, wherein the target test object is the entry function;
the cutting of the ground state test case based on the set target test object to obtain the target test case comprises the following steps:
taking the incoming parameters of the entry function as test messages in a target test case;
taking the return value of the entry function as a message check point in the target test case;
taking the incoming parameters and the return values of all key sub-functions which are not in the set range in the entry function as baffle data in the target test case;
and taking the data form obtained after the entry function executes each database operation as a data form check point in the target test case.
5. The method of claim 1, wherein the target test object is any key sub-function in the entry function;
the cutting of the ground state test case based on the set target test object to obtain the target test case comprises the following steps:
taking the incoming parameters of the key subfunction as test messages in a target test case;
taking the return value of the key subfunction as a message check point in the target test case;
taking the incoming parameters and the return values of each key sub-function called for each external interface in the key sub-functions as baffle data in the target test case;
and taking the final data form obtained after the key subfunction is executed as a data form check point in the target test case.
6. The method of any of claims 1-5, wherein the database operation records are stored in order of execution;
the sequentially restoring the databases in a reverse order mode according to the execution sequence of the operation records of the databases based on the operation records of the databases and the recovery operation records of the databases to obtain the data form of the target test case before recording comprises the following steps:
sequentially acquiring the operation records of each database according to the sequence opposite to the execution sequence;
for any database operation record in the database operation records, if the database operation record indicates any one of query operation, deletion operation and update operation to the database, operating the database according to the database recovery operation record corresponding to the database operation record; if the database operation record indicates that the database is subjected to insertion operation, ignoring a database recovery operation record corresponding to the database operation record;
and after finishing the processing of the last database operation record in the database operation records, obtaining the data form of the target test case before recording.
7. The method of claim 1, wherein the target test case comprises a first message return value and a first data modality of a database;
the playing back the target test case in the recording environment includes:
recording a second message return value and a second data form of the database by replaying the target test case;
verifying the second message return value based on the first message return value to obtain a first verification result, and verifying the second data form based on the first data form to obtain a second verification result;
and if the first check result and the second check result are respectively consistent, determining that the business system is correctly upgraded under the target test object.
8. An automated testing apparatus, comprising:
the target test case obtaining unit is used for cutting the ground state test case based on a set target test object to obtain a target test case; the basic state test case is obtained by recording an entry function involved in the period that the service request runs in the service system; the base state test case comprises incoming parameters and return values of the entry function, incoming parameters and return values of all key sub-functions in the entry function, database operation records of the entry function in the execution process and database recovery operation records corresponding to the database operation records respectively;
a data form obtaining unit, configured to sequentially restore the databases in a reverse order manner according to the execution order of the operation records of the databases based on the operation records of the databases and the recovery operation records of the databases, so as to obtain a data form of the target test case before recording;
and the test case playback unit is used for playing back the target test case under the data form.
9. A computer device, comprising:
a memory for storing a computer program;
a processor for calling a computer program stored in said memory, for executing the method according to any one of claims 1-7 in accordance with the obtained program.
10. A computer-readable storage medium having stored thereon computer-executable instructions for causing a computer to perform the method of any one of claims 1-7.
CN202111432389.3A 2021-11-29 2021-11-29 Automatic testing method and device Pending CN113986766A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111432389.3A CN113986766A (en) 2021-11-29 2021-11-29 Automatic testing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111432389.3A CN113986766A (en) 2021-11-29 2021-11-29 Automatic testing method and device

Publications (1)

Publication Number Publication Date
CN113986766A true CN113986766A (en) 2022-01-28

Family

ID=79732440

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111432389.3A Pending CN113986766A (en) 2021-11-29 2021-11-29 Automatic testing method and device

Country Status (1)

Country Link
CN (1) CN113986766A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114968829A (en) * 2022-08-02 2022-08-30 平安银行股份有限公司 Full link pressure test method, electronic device and storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114968829A (en) * 2022-08-02 2022-08-30 平安银行股份有限公司 Full link pressure test method, electronic device and storage medium

Similar Documents

Publication Publication Date Title
WO2020062673A1 (en) Smart contract test method, storage medium, test terminal and test device
US6182245B1 (en) Software test case client/server system and method
CN107077413B (en) Data driven test framework
US20170372247A1 (en) Methods, systems, and articles of manufacture for implementing software application development and releases
US11442920B2 (en) Graph database system
US8001091B2 (en) Apparatus, system, and method for hierarchical rollback of business operations
WO2020108289A1 (en) Database system, node and method
CN115039084A (en) Unit testing of components of a dataflow graph
US11334536B2 (en) Specifying and applying rules to data
CN110674161A (en) Method, system, storage medium and SQL operation platform for online SQL
CN110058962A (en) Determine the method, equipment and computer program product of the consistency level of virtual machine snapshot
CN111782207A (en) Method, device and equipment for generating task stream code and storage medium
CN113535141A (en) Database operation code generation method and device
CN113986766A (en) Automatic testing method and device
CN111694738B (en) Method for generating SQL test script
CN113312259A (en) Interface testing method and device
US11443047B2 (en) Systems and methods for use in validating artifacts for deployment
US11836071B2 (en) Method and apparatus creating test environments for blockchain systems
CN114385722A (en) Interface attribute consistency checking method and device, electronic equipment and storage medium
US8856069B2 (en) Combined save and validation logic
US11966325B2 (en) Codeless automatic testing framework
CN115145831B (en) Non-invasive test data recovery method and system
Ye An Evaluation on Using Coarse-grained Events in an Event Sourcing Context and its Effects Compared to Fine-grained Events
CN114610644A (en) Method and device for testing database
CN117593092A (en) On-line management method, system, equipment and storage medium for commodity sale

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination