A method, device, equipment and medium for database testing
By parsing business process source code to determine call paths and construct test data based on service interface calls, the method addresses the challenge of pre-launch database testing, enhancing stability and reducing post-launch defects.
Patent Information
- Application Number
- CN202011298070.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-18
- Publication Date
- 2024-12-17
- Estimated Expiration
- 2040-11-18
AI Technical Summary
Existing database testing methods can only be performed after the business product is launched, leading to potential code changes that trigger new database defects and compromise stability.
Parse the business process source code to determine business call paths, calculate the number of calls for each internal service interface, and construct test data based on these proportions to test and optimize the database before launch.
Accurately tests and optimizes the database before deployment, improving stability and reducing the risk of post-launch defects.
Smart Images

Figure CN113391991B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of testing technology, and in particular to a method, device, equipment and medium for database testing. Background Art
[0002] With the development of the Internet and computer technology, business products such as websites and applications usually generate a large amount of business data that needs to be stored in the process of providing online business services. Therefore, the performance requirements for the database of business products are becoming higher and higher.
[0003] Under the existing technology, in order to ensure the stability of the database, the database of the business product is usually tested based on the business interaction data obtained after the business product is launched, and then the database is optimized based on the test results.
[0004] However, database testing and optimization can only be performed after the business product is launched, which may cause code changes and trigger new database defects, resulting in poor database stability. Summary of the invention
[0005] The embodiments of the present application provide a method, apparatus, device and medium for testing a database, which are used to solve the problem of being unable to accurately test and optimize the database before the business product goes online when testing the database of the business product, thereby improving the stability of the database.
[0006] In one aspect, a method for database testing is provided, comprising:
[0007] Parsing the business process source code of the target business object, and obtaining at least one business call path based on the parsing result, wherein the business call path is composed of business process nodes and internal service interfaces between the business process nodes;
[0008] According to at least one business call path, determine the number of times each internal service interface corresponding to each business process node is called;
[0009] Determine the business proportion of each business process node according to the number of calls of each internal service interface corresponding to each business process node;
[0010] Construct corresponding test data according to the business proportion of each business process node;
[0011] Based on the test data, the database corresponding to the target business object is tested to obtain the database test results.
[0012] In one aspect, a database testing device is provided, comprising:
[0013] A parsing unit, used to parse the business process source code of the target business object, and obtain at least one business call path based on the parsing result, wherein the business call path is composed of business process nodes and internal service interfaces between the business process nodes;
[0014] A first determining unit, configured to determine, according to at least one business call path, the number of times each internal service interface corresponding to each business process node is called;
[0015] The second determining unit is used to determine the business proportion of each business process node according to the number of times each internal service interface corresponding to each business process node is called;
[0016] A construction unit, used to construct corresponding test data according to the business proportion of each business process node;
[0017] The test unit is used to test the database corresponding to the target business object according to the test data and obtain the database test result.
[0018] Preferably, the parsing unit is used to:
[0019] Parse the business process source code to obtain the parsing results;
[0020] Based on the analysis results, determine each business process node set in the business process source code, and the internal service interface called between each business process node;
[0021] Generate a business process diagram based on each business process node and the internal service interface called between each business process node;
[0022] According to the business process diagram, determining a starting node and at least one ending node in each business process node;
[0023] Determine a business call path corresponding to the business process diagram according to the start node and at least one end node;
[0024] A business call path includes: business process nodes between a start node and an end node, and internal service interfaces called between the business process nodes.
[0025] Preferably, the parsing unit is used to:
[0026] Obtain the state machine according to each business process node and the internal service interface called between each business process node;
[0027] The state machine is processed by image conversion to obtain the corresponding business process diagram.
[0028] Preferably, the first determining unit is used for:
[0029] For each business process node except the start node, perform the following steps:
[0030] From at least one business call path, extract at least one local call path corresponding to a business process node, each local call path includes: a business process node between a starting node and a business process node, and an internal service interface called between each business process node;
[0031] Determine the internal service interface in at least one local call path as the internal service interface corresponding to a business process node;
[0032] The number of times each internal service interface corresponding to a business process node is called by at least one local call path is determined as the corresponding number of times called.
[0033] Preferably, the second determining unit is used for:
[0034] According to the analysis results, determine the internal service interface called by each internal service interface;
[0035] Determine the business weight of the corresponding internal service interface according to the internal service interface called by each internal service interface;
[0036] According to the number of calls and the business weight of each internal service interface corresponding to each business process node, the business proportion of the corresponding business process node is obtained.
[0037] Preferably, the second determining unit is used for:
[0038] For each internal service interface, perform the following steps:
[0039] If it is determined that an internal service interface does not call an external service interface, then the business weight of the internal service interface is determined to be a specified weight;
[0040] If it is determined that an internal service interface calls at least one external service interface, a business weight of an internal service interface is determined according to the at least one external service interface and a corresponding interface coefficient.
[0041] Preferably, the construction unit is used for:
[0042] Get the database table information of the database;
[0043] Generate multiple database operation statements based on the business proportion of each business process node and database table information;
[0044] Execute each database operation statement and store the constructed test data in the database, where the proportion of each type of data in the test data is the business proportion.
[0045] On the one hand, a control device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the steps of any one of the above-mentioned database testing methods when executing the program.
[0046] On the one hand, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the steps of any of the above-mentioned database testing methods are implemented.
[0047] In one aspect, a computer program product or a computer program is provided, the computer program product or the computer program comprising computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method provided in any of the above-mentioned various optional implementations of the database test.
[0048] In a method, device, equipment and medium for database testing provided by an embodiment of the present application, the business process source code of the target business object is parsed to obtain each business call path, and the corresponding business proportion is determined according to the number of calls of each internal service interface corresponding to each business process node in each business call path, and test data is constructed according to the business proportion, and then the database of the business product is tested according to the test data to obtain the test result. In this way, the problem of being unable to accurately test and optimize the database before the business product is launched is solved, and the stability of the database after the business product is launched is improved.
[0049] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0051] Figure 1 This is a schematic diagram of the architecture of a database testing system in an implementation manner of the present application;
[0052] Figure 2 This is a flowchart of a method for database testing in an implementation manner of the present application;
[0053] Figure 3This is an example diagram of a business process diagram in an implementation manner of this application;
[0054] Figure 4 This is an example diagram of a call path table in an implementation manner of the present application;
[0055] Figure 5a This is an example of a service call path in the implementation method of this application. Figure 1 ;
[0056] Figure 5b This is an example of a service call path in the implementation method of this application. Figure 2 ;
[0057] Figure 6 A schematic diagram of the system architecture of a database testing method in an embodiment of the present application;
[0058] Figure 7 A schematic diagram of the structure of a database testing device in an embodiment of the present application;
[0059] Figure 8 It is a structural schematic diagram of a control device in an implementation manner of the present application. DETAILED DESCRIPTION
[0060] In order to make the purpose, technical solution and beneficial effects of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0061] First, some terms involved in the embodiments of the present application are explained to facilitate understanding by those skilled in the art.
[0062] Terminal device: can be a mobile terminal, a fixed terminal or a portable terminal, such as a mobile phone, a station, a unit, a device, a multimedia computer, a multimedia tablet, an Internet node, a communicator, a desktop computer, a laptop computer, a notebook computer, a netbook computer, a tablet computer, a personal communication system device, a personal navigation device, a personal digital assistant, an audio / video player, a digital camera / camcorder, a positioning device, a television receiver, a radio broadcast receiver, an electronic book device, a gaming device or any combination thereof, including accessories and peripherals of these devices or any combination thereof. It is also foreseeable that the terminal device can support any type of interface for the user (such as a wearable device), etc.
[0063] Server: It can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, and big data and artificial intelligence platforms.
[0064] Artificial Intelligence (AI): It is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science that attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines, so that machines have the functions of perception, reasoning and decision-making.
[0065] Artificial intelligence technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level and software-level technologies. The basic technologies of artificial intelligence generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics and other technologies. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0066] Cloud storage: is a new concept extended and developed from the concept of cloud computing. Distributed cloud storage system (hereinafter referred to as storage system) refers to a storage system that uses cluster applications, grid technology, distributed storage file systems and other functions to bring together a large number of different types of storage devices (storage devices are also called storage nodes) in the network through application software or application interfaces to work together and provide external data storage and business access functions.
[0067] At present, the storage method of the storage system is: create a logical volume, and when creating a logical volume, allocate physical storage space for each logical volume. The physical storage space may be composed of disks of a storage device or several storage devices. The application stores data on a logical volume, that is, stores the data on the file system. The file system divides the data into many parts, each of which is an object. The object contains not only data but also additional information such as data identification. The file system writes each object into the physical storage space of the logical volume, and the file system records the storage location information of each object, so that when the application requests to access the data, the file system can allow the application to access the data according to the storage location information of each object.
[0068] The process of the storage system allocating physical storage space to a logical volume is as follows: based on the estimated capacity of the objects stored in the logical volume (this estimate usually has a large margin relative to the capacity of the actual objects to be stored) and the grouping of the Redundant Array of Independent Disks (RAID), the physical storage space is pre-divided into stripes. A logical volume can be understood as a stripe, thereby allocating physical storage space to the logical volume.
[0069] Database: In short, it can be regarded as an electronic file cabinet - a place to store electronic files, where users can add, query, update, delete, etc. The so-called "database" is a collection of data stored together in a certain way, which can be shared with multiple users, has as little redundancy as possible, and is independent of the application.
[0070] Database Management System: A computer software system designed for managing databases, generally with basic functions such as storage, retrieval, security, and backup. Database management systems can be classified according to the database model they support, such as relational, XML, or according to the type of computer they support, such as server clusters, mobile phones; or according to the query language used, such as Structured Query Language (SQL), XQuery; or according to the performance focus, such as maximum scale, maximum operating speed; or other classification methods. Regardless of the classification method used, some database management systems can cross categories, for example, supporting multiple query languages at the same time.
[0071] State machine: It is composed of state registers and combinational logic circuits. It can transfer states according to pre-set states based on control signals. It is the control center that coordinates related signal actions and completes specific operations. The state machine is an abstraction of the real world and a logically rigorous mathematical abstraction, so it is obviously very suitable for use in the digital field. It can be applied to various levels, such as hardware design, compiler design, and programming to implement various specific business logics.
[0072] Flowchart Drawing Editor (yEd Graph Editor): is a powerful flowchart drawing software that can create flowcharts, intention diagrams, graphs, network structure diagrams and other charts, providing complete flowchart drawing functions.
[0073] Sysbench framework: is an open source multi-threaded performance testing tool that can perform performance tests in memory / threads / databases, etc.
[0074] Lua: is a small scripting language. It is designed to provide flexible expansion and customization functions for applications by being flexibly embedded in them. Lua is written in standard C and can be compiled and run on almost all operating systems and platforms.
[0075] The design concept of the embodiments of the present application is introduced below.
[0076] With the development of Internet technology and computer technology, business products such as websites or applications usually generate a large amount of business data that needs to be stored in the process of providing online business services. Therefore, the performance requirements for the database of business products are getting higher and higher.
[0077] Under existing technologies, the following two methods are usually used to ensure the stability of the database:
[0078] The first method is: after the business product is launched, the business interaction data of the business product is obtained, and the database is tested according to the business interaction data, the test results are obtained, and the database is optimized according to the test results.
[0079] However, with this approach, the database can only be tested and optimized after the business product is launched. When optimizing the database, code changes may be triggered, which in turn trigger new database defects, resulting in poor database stability and poor user experience.
[0080] The second way is to build test data or test models based on the tester's experience.
[0081] However, this method lacks theoretical derivation basis and the accuracy of the test results is poor.
[0082] Therefore, there is an urgent need for a technical solution for database testing to solve the problem of being unable to accurately test and optimize the database before the business product goes online when testing the database of the business product, so as to improve the stability of the database.
[0083] In view of the above analysis and consideration, a database testing solution is provided in the embodiment of the present application, in which the business process source code of the target business object is parsed to obtain each business call path, and the corresponding business proportion is determined according to the business weight and the number of calls of each internal service interface corresponding to each business process node in each business call path, and the test data is constructed according to the business proportion, and then the database of the business product is tested according to the test data to obtain the test results. In this way, the problem of not being able to accurately test the database before the business product goes online is solved, and the stability of the database after the business product goes online is improved.
[0084] To further illustrate the technical solution provided by the embodiment of the present application, this is described in detail below in conjunction with the accompanying drawings and specific implementation methods. Although the embodiment of the present application provides the method operation steps shown in the following embodiments or drawings, more or fewer operation steps may be included in the method based on routine or no creative labor. In the steps where there is no necessary causal relationship logically, the execution order of these steps is not limited to the execution order provided by the embodiment of the present application. The method can be executed in the order of the method shown in the embodiment or drawings or in parallel during the actual processing process or when the device is executed.
[0085] The terms "first", "second", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0086] See also Figure 1 As shown, it is a schematic diagram of the architecture of a database test system. The database 103 test system includes a control device 101, a business device 102 and a database 103. Among them, the database 103 can be a separate device, or it can be integrated in the business device 102. The control device 101 and the business device 102 can also be integrated in the same device, or they can be different devices. In the embodiment of the present application, only the control device 101, the business device 102 and the database 103 are different devices as an example for explanation. In actual application, it can be set according to the actual application scenario, and it is not limited here.
[0087] Business device 102: can be a server or a terminal device, and can interact with other devices by running the business process source code of the target business object to provide business services to users. Business device 102 stores input and output data in the process of running the business process source code through database 103.
[0088] For example, the business device 102 is a news server, and the target business object is a news website. After the news website is online, the user sends an access request message to the news server through the news website of the user terminal. The news server executes the corresponding business process source code of the news website according to the user's access request message, returns the corresponding access response message to the user terminal, and stores the input and output data such as the access request message in the interaction process to the database 103.
[0089] The control device 101 can be a server or a terminal device, which is used to parse the business process source code of the target business object, obtain each business call path, and determine the business proportion of each business process node in each business call path based on each business call path, and use random numbers to construct test data according to the business proportion of each business process node, and test the database 103 based on the test data, and then optimize the database 103 based on the test results.
[0090] Optionally, test data and test results and other data can be stored in cloud storage and database. The database can be managed by a database management system.
[0091] In an embodiment of the present application, based on the big data processing technology in artificial intelligence technology, before the target business object goes online, the business proportion of data of different data types can be determined according to the calls to different internal service interfaces determined by the business process source code of the target business object, and then test data can be constructed according to the business proportion, so that the database 103 can be optimized before the target business object is put online, thereby ensuring the stability of the database 103 after the target business object is put online, avoiding the possibility of triggering new defects by repairing the database 103 after the target business object is put online, and compared with the method of constructing test data or test models according to manual experience in traditional technologies, the accuracy of the test results is greatly improved.
[0092] See also Figure 2 The figure is a flowchart of a method for database testing provided by the present application. The specific process of the method is as follows:
[0093] Step 200: The control device parses the business process source code of the target business object, and obtains at least one business call path based on the parsing result.
[0094] Specifically, when executing step 200, the following steps may be adopted:
[0095] S2001: The control device parses the business process source code of the target business object, obtains the parsing result, and based on the parsing result, determines the business process nodes set in the business process source code, the internal service interfaces called between the business process nodes, and the internal service interfaces called by the internal service interfaces.
[0096] Specifically, the control device determines the business process nodes set in the business process source code according to the macro definition, and scans the business process source code to determine the internal service interfaces called between the business process nodes and the internal service interfaces called by the internal service interfaces.
[0097] The target business object is a business product that provides business services, such as websites and applications. The business process source code is used to provide business services. The business process source code is provided with each business process node and an internal service interface called between each business process node. The external service interface is an interface used by the target business object to interact with an external system.
[0098] For example, the external system is a user terminal and a server that interacts with the target business object. The internal service interface can be a middle call, a relay call, etc. The external service interface can be a Hyper Text Transport Protocol (HTTP) request, a User Datagram Protocol (UDP) request, etc.
[0099] In this way, the business process nodes set in the business process source code, each internal service interface, and the internal service interface called by each internal service interface can be determined.
[0100] S2002: The control device generates a business process diagram according to each business process node and the internal service interface called between each business process node.
[0101] Specifically, the control device obtains a state machine according to each business process node and an internal service interface called between each business process node, and performs image conversion processing on the state machine to obtain a corresponding business process diagram.
[0102] In one implementation, the control device uses each business process node as a state in a state machine, and determines the edges between corresponding states in the state machine according to the internal service interface between each business process node, thereby generating a state machine corresponding to the business process source code. The control device uses a flowchart drawing application to convert the obtained state machine into a corresponding business process diagram.
[0103] Optionally, the flowchart drawing application may be yEd Graph Editor or the like.
[0104] See also Figure 3 The figure shows an example of a business process diagram. Figure 3 In the business process diagram, the business process nodes are: v_start, v_init, v_paying, v_payed_fial, v_payed_succ, and the internal service interfaces are: entpay_crt_c, entpay_upd_c_10, entpay_upd_c_30, entpay_upd_c_20.
[0105] It should be noted that there may be one or more business process diagrams. In the embodiment of the present application, only the generation of test data for one business process diagram is used as an example for explanation. Similarly, test data may be generated for multiple acquired business process diagrams, which will not be elaborated here.
[0106] In this way, the business process diagram corresponding to the business process source code can be obtained.
[0107] S2003: The control device determines a start node and at least one end node in each business process node according to the business process diagram.
[0108] Specifically, the control device uses a path generation application to determine a call path table corresponding to the business process graph, and determines a start node and an end node in each business process node according to a specified separator in the call path table.
[0109] The path generation application is used to determine the element name in the business process diagram. The element name includes the business process node and the name of the internal service interface between each business process node. If there is no internal service interface between the business process nodes, the specified element name is obtained, and the specified separator is generated according to the specified element name. The end node can be one or more. A business process diagram usually contains only one start node.
[0110] Optionally, the business process source code may correspond to one business process diagram or multiple business process diagrams. In the embodiment of the present application, only one business process diagram is used as an example for illustration. Similarly, the starting node and the ending node of other business process diagrams may be determined, and then the corresponding test data may be generated, which will not be elaborated here.
[0111] In actual applications, the specified element name can be set according to the actual application scenario, or can be set to empty, and there is no restriction here.
[0112] Optionally, the path generation application can generate tools (graphwalker) for use cases based on the test model.
[0113] It should be noted that, before executing S2003, the end node in the business process diagram is connected to the start node, and there is no internal service interface between the end node and the start node.
[0114] For example, see Figure 4 As shown in the figure, it is an example diagram of a call path table. Assume that the specified separator is: {"currentElementName":""}, the specified element name is empty, and the control device uses graphwalker to output in sequence Figure 3 The names of the elements in each path in the business process diagram. Figure 3 The call path table corresponding to the business process diagram in is: {"currentElementName":"v_start"}, {"currentElementName":"entpay_crt_c"}, …, {"currentElementName":"v_payed_succ"}, {"currentElementName":""}, {"currentElementName":"v_start"}, {"currentElementName":"entpay_crt_c"}, …, {"currentElementName":"v_payed_fial"}, {"currentElementName":""}.
[0115] The control device then determines, based on {"currentElementName":""}, that v_payed_succ and v_payed_fial are the end nodes, and {"currentElementName":"v_start"} is the start node.
[0116] S2004: The control device determines a service call path corresponding to the service process diagram according to the start node and at least one end node.
[0117] Specifically, the control device divides each element name in the call path table into multiple sequences according to the termination node, and respectively composes each element name in each sequence into a corresponding service call path.
[0118] A business call path includes: business process nodes between a starting node and an ending node, and internal service interfaces called between business process nodes. The number of business call paths can be one or more.
[0119] For example, see Figure 5a The following is an example of a business call path. Figure 1. See Figure 5b The following is an example of a business call path. Figure 2 The control device will Figure 4 The call path table in is divided into two business call paths. The call path table corresponding to one business call path is: {"currentElementName":"v_start"}, {"currentElementName":"entpay_crt_c"}, ..., {"currentElementName":"v_payed_succ"}, and the call path table corresponding to one business call path is: {"currentElementName":"v_start"}, {"currentElementName":"entpay_crt_c"}, ..., {"currentElementName":"v_payed_fial"}.
[0120] In this way, the various business call paths that can be executed during the operation can be determined based on the business process diagram.
[0121] Step 201: The control device determines the number of times each internal service interface corresponding to each business process node is called according to at least one business call path.
[0122] Specifically, when executing step 201, the control device may respectively adopt the following steps for each service process node except the start node:
[0123] S2011: The control device extracts at least one local call path corresponding to a business process node from at least one business call path.
[0124] The number of local call paths may be one or more, and each local call path includes: a business process node between a starting node and the business process node, and an internal service interface called between each business process node.
[0125] That is, the local call path from the start node to the business process node.
[0126] S2012: The control device determines the internal service interface in the at least one local call path as the internal service interface corresponding to the one business process node.
[0127] Specifically, the control device determines the internal service interface in each local call path corresponding to the business process node as the internal service interface corresponding to the business process node.
[0128] That is to say, all internal service interfaces before the business process node are used as the internal service interfaces corresponding to the business process node.
[0129] S2013: The control device determines the number of times each internal service interface corresponding to the one business process node is called by the at least one local call path as the corresponding number of times called.
[0130] Specifically, the control device performs the following steps for each internal service interface corresponding to the business process node: determining the number of calls of the above-mentioned local call path containing the internal service interface, and using the number as the number of times the internal service interface is called.
[0131] It should be noted that if there are two business process nodes with the same element name but different path positions in the business call path, the two business process nodes are different business process nodes. Similarly, if there are two internal service interfaces with the same element name but different path positions in the business call path, the two internal service interfaces are different internal service interfaces. Furthermore, since the local call paths corresponding to different business process nodes are called differently, the number of times the same internal service interface corresponding to different business process nodes is called may be different.
[0132] In this way, the number of times each internal service interface is called can be determined.
[0133] Step 202: The control device determines the business proportion of each business process node according to the number of times each internal service interface corresponding to each business process node is called.
[0134] Specifically, the control device determines the business weight of the corresponding internal service interface according to the internal service interface called by each internal service interface, and obtains the business proportion of the corresponding business process node according to the number of calls and business weight of each internal service interface corresponding to each business process node.
[0135] The following two methods can be used to determine the service weight of each internal service interface:
[0136] The first manner is: if it is determined that an internal service interface does not call an external service interface, the control device determines that the service weight of the internal service interface is a specified weight.
[0137] Optionally, the specified weight may be 1. In actual applications, the specified weight may be set according to actual application scenarios and is not limited here.
[0138] The second method is: if it is determined that an internal service interface calls at least one external service interface, the business weight of the internal service interface is determined according to the external service interface called by the internal service interface and the corresponding interface coefficient.
[0139] Specifically, the product of the external service interface called by the internal service interface of the control device and the corresponding interface coefficient is calculated, and the sum of the product and the specified weight is used as the business weight of the internal service interface.
[0140] The interface coefficients of different external service interfaces can be the same or different, and can be different preset values. The interface coefficient can be determined according to the business volume of the external call interface. In actual applications, the interface coefficient can be set according to the actual application scenario, and is not limited here.
[0141] Among them, when determining the business proportion of each business process node, the following steps can be adopted:
[0142] S2021: The control device performs the following steps for each internal service interface of each business process node: determining the product of the number of times the internal service interface is called and the corresponding business weight.
[0143] S2022: The control device uses the sum of the products corresponding to the business process node as the business quantity of the business process node.
[0144] S2023: The control device determines the business proportion of each business process node according to the business quantity of each business process node.
[0145] In one implementation, the control device performs the following steps for each business process node: determining the sum of the business quantities, and determining the ratio of the business quantity of a business process node to the sum, to obtain the business proportion of the business process node.
[0146] For example, the control device determines that the internal service interface corresponding to v_init is entpay_crt_c, the number of times entpay_crt_c is called is 2, and the service weight is 1, then the number of node services corresponding to v_init is determined to be 2*1=2.
[0147] The control device determines that the internal service interfaces corresponding to v_paying are entpay_crt_c and entpay_upd_c_10. The number of times entpay_crt_c is called is 2, and the service weight is 1. The number of times entpay_upd_c_10 is called is 2, and the service weight is 2. Therefore, the number of node services corresponding to v_paying is determined to be 2*1+2*2=6.
[0148] The control device determines that the internal service interfaces corresponding to v_payed_fial are entpay_crt_c, entpay_upd_c_10, and entpay_upd_c_30. The number of times entpay_crt_c is called is 1, and the service weight is 1, the number of times entpay_upd_c_10 is called is 1, and the service weight is 2, and the number of times entpay_upd_c_30 is called is 1, and the service weight is 2. Then, the number of node services corresponding to v_payed_fial is determined to be 1*1+1*2+1*2=5.
[0149] The control device determines that the internal service interfaces corresponding to v_payed_succ are entpay_crt_c, entpay_upd_c_10, and entpay_upd_c_20. The number of times entpay_crt_c is called is 1, and the service weight is 1, the number of times entpay_upd_c_10 is called is 1, and the service weight is 2, and the number of times entpay_upd_c_20 is called is 1, and the service weight is 2. Then, the number of node services corresponding to v_payed_succ is determined to be 1*1+1*2+1*2=5.
[0150] The control device determines that the business proportion corresponding to v_init is 11%, the business proportion corresponding to v_paying is 33%, the business proportion corresponding to v_payed_fial is 28%, and the business proportion corresponding to v_payed_succ is 28%.
[0151] Step 203: The control device constructs corresponding test data according to the business proportion of each business process node.
[0152] Specifically, when executing step 203, the control device may use a multi-threaded performance testing tool to perform the following steps:
[0153] S2031: The control device obtains database table information of the database.
[0154] The database table information may include: the name, primary key and unique key of the database table. The database table information is used to insert data into the database table in subsequent steps.
[0155] Furthermore, if the database table does not exist in the database, a database operation statement for creating the database table and a database operation statement for adding a primary key and a unique key may be generated first.
[0156] S2032: The control device generates multiple database operation statements according to the business proportion of each business process node and the database table information.
[0157] Specifically, the database operation statement is used to perform database operations on the corresponding database table according to the database table information, such as inserting data into the database table. The data in the database table statement is filled with random numbers, and the data type of the filled random numbers is generated according to the business ratio. The number of database operation statements is determined according to the required data volume.
[0158] In this way, in subsequent steps, a specified amount of test data can be inserted into the database table by executing multiple database operation statements.
[0159] In actual applications, the specified data volume can be set according to the actual application scenario and is not limited here.
[0160] Optionally, each database operation statement may be an SQL statement for inserting data, such as an SQL statement: insert into table1(field1, field2)values(value1, value2). That is, data value1 is inserted into the field1 area in table 1, and data value2 is inserted into the field2 area in table 1. value1 and value2 of each SQL statement are random numbers of corresponding data types generated by the control device according to the business proportion.
[0161] That is to say, according to the business proportion, the proportion of data of each data type is determined, and then according to the proportion of data of each data type, random numbers are filled to obtain test data.
[0162] In actual applications, database operation statements can be set according to actual application scenarios and are not limited here.
[0163] S2033: The control device executes each database operation statement and stores the constructed test data in the database.
[0164] Specifically, the control device generates a script according to the generated multiple database operation statements, and executes the generated script to fill the random numbers into the database, so that the database stores a specified amount of test data.
[0165] Among them, the proportion of each data type in the test data is the business proportion.
[0166] Optionally, the multi-threaded performance testing tool may be a sysbench framework.
[0167] In one implementation, the control device uses a sysbench framework to generate multiple database operation statements, generates a lua script based on each database operation statement, and executes the generated script to perform data construction.
[0168] In this way, the test data can be filled in the database for data testing in subsequent steps.
[0169] Step 204: The control device tests the database corresponding to the target business object according to the test data to obtain a database test result.
[0170] Specifically, when executing step 204, the following steps may be adopted:
[0171] S2041: The control device calls a test statement to perform a stress test on the database through a test application program to obtain a stress test result of the database.
[0172] Specifically, the control device calls the test statement through the test application and the test data in the database to perform a stress test on the database and obtain the stress test result of the database.
[0173] Optionally, the stress test can be: a test of the maximum capacity of the database, that is, testing the maximum amount of data that the database can store, or a test of the maximum capacity that the business device needs to support, that is, testing the capacity of storage resources required by the business device in the process of running the business process source code.
[0174] Furthermore, the control device may also mark the test data when constructing the test data, and delete the test data after the test is completed to avoid affecting the test environment data.
[0175] In one implementation, after the control device determines that the test is finished, the test data is deleted by using a one-key clear of the sysbench framework.
[0176] S2042: Control the device to obtain the operating environment data and operating status of the database during the test.
[0177] Specifically, the operating environment data may be a central processing unit (CPU), etc., and the operating status may be whether the database crashes or freezes, etc.
[0178] S2043: The control device evaluates the database according to the operating environment data and the operating status to obtain a performance test result of the database.
[0179] Optionally, the performance test results may include database performance and optimization suggestions.
[0180] In one implementation, the control device uses a database performance monitoring application (mysqlreport), uses the operating environment data and real-time operating status of the database, and evaluates the database to obtain a performance test result of the database.
[0181] Furthermore, in actual applications, other functions of the database may also be tested according to actual application scenarios, which are not limited here.
[0182] Furthermore, the control device sends the database test results to the control center, and can use push or other methods to notify the tester of the test results, so that the tester can optimize the database according to the test results.
[0183] See also Figure 6 The figure shows a schematic diagram of the system architecture of a database testing method. It includes a model based testing (MBT) module, a control module and a test module. The MBT module includes: a system source code parsing module, an image conversion module and a path table conversion module; the control module includes: a call path module, a business proportion module, a test result module, a result output module and a notification module; the test module includes: a data construction module, a test execution module, a data cleaning module and an environmental information collection module.
[0184] Among them, the system source code parsing module is used to parse the business process source code, and based on the parsing results, obtain each business process node, the internal service interface called between each business process node, and the internal service interface called by each internal service interface.
[0185] Image conversion module: used to generate a business process diagram based on each business process node and the internal service interface called between each business process node.
[0186] Path table conversion module: used to convert the business process diagram into a call path table.
[0187] Call path module: used to divide each business process node in the call path table according to the termination node to obtain each call path module.
[0188] Business proportion module: It is used to determine the number of calls of each internal service interface corresponding to each business process node according to each business call path, and determine the business proportion of the corresponding business process node according to the number of calls of each internal service interface corresponding to each business process node and the business weight.
[0189] Data construction module: used to construct corresponding test data according to the business proportion of each business process node.
[0190] Test execution module: used to test the database according to the test data and send the stress test results to the test result module.
[0191] Data cleaning module: used to clean and delete the test data after the test is completed.
[0192] Environmental information collection module: used to collect the operating environment data and operating status of the database.
[0193] Test result module: used to evaluate the database according to the operating environment data and operating status, obtain the performance test results of the database, and send the stress test results and performance test results to the result output module.
[0194] Result output module: used to send stress test results and performance test results to the control center.
[0195] Notification module: used to notify relevant personnel of test results through push notification or other means.
[0196] In an embodiment of the present application, before a business product is launched, the data ratio of each data type (i.e., the business ratio) that may be generated by the business product in the business service process is determined based on the internal service interface called by each business process node in the business process source code of the business product and the internal service interface called by each internal service interface, and a random number is used to construct test data according to the data ratio, and the database of the business product is tested based on the test tool and the test data to evaluate the maximum storage capacity of the database and the database performance, so that a trustworthy evaluation result is obtained before the business product is launched, and then the database can be optimized based on the evaluation result, so that the database can reach the optimal state before the business product is launched, thereby reducing the possibility of code changes and new defects caused by database repair after the business product is launched, and improving the stability and security of the database. Furthermore, there is no need to rely on the experience of testers to construct test data and test models, which improves the accuracy of the test results, ensures the stable and safe operation of the business product after it is launched, and improves the user experience of the business product.
[0197] Based on the same inventive concept, a device for database testing is also provided in the embodiment of the present application. Since the principle of solving the problem by the above-mentioned device and equipment is similar to that of a method for database testing, the implementation of the above-mentioned device can refer to the implementation of the method, and the repeated parts will not be repeated.
[0198] like Figure 7 , which is a schematic diagram of the structure of a database testing device provided in an embodiment of the present application. A database testing device includes:
[0199] The parsing unit 701 is used to parse the business process source code of the target business object, and obtain at least one business call path based on the parsing result, wherein the business call path is composed of business process nodes and internal service interfaces between the business process nodes;
[0200] A first determining unit 702 is used to determine the number of times each internal service interface corresponding to each business process node is called according to at least one business call path;
[0201] The second determining unit 703 is used to determine the business proportion of each business process node according to the number of times each internal service interface corresponding to each business process node is called;
[0202] A construction unit 704 is used to construct corresponding test data according to the business proportion of each business process node;
[0203] The testing unit 705 is used to test the database corresponding to the target business object according to the test data to obtain the database test result.
[0204] Preferably, the parsing unit 701 is used for:
[0205] Parse the business process source code to obtain the parsing results;
[0206] Based on the analysis results, determine each business process node set in the business process source code, and the internal service interface called between each business process node;
[0207] Generate a business process diagram based on each business process node and the internal service interface called between each business process node;
[0208] According to the business process diagram, determining a starting node and at least one ending node in each business process node;
[0209] Determine a business call path corresponding to the business process diagram according to the start node and at least one end node;
[0210] A business call path includes: business process nodes between a start node and an end node, and internal service interfaces called between the business process nodes.
[0211] Preferably, the parsing unit 701 is used for:
[0212] Obtain the state machine according to each business process node and the internal service interface called between each business process node;
[0213] The state machine is processed by image conversion to obtain the corresponding business process diagram.
[0214] Preferably, the first determining unit 702 is used for:
[0215] For each business process node except the start node, perform the following steps:
[0216] From at least one business call path, extract at least one local call path corresponding to a business process node, each local call path includes: a business process node between a starting node and a business process node, and an internal service interface called between each business process node;
[0217] Determine the internal service interface in at least one local call path as the internal service interface corresponding to a business process node;
[0218] The number of times each internal service interface corresponding to a business process node is called by at least one local call path is determined as the corresponding number of times called.
[0219] Preferably, the second determining unit 703 is used for:
[0220] According to the analysis results, determine the internal service interface called by each internal service interface;
[0221] Determine the business weight of the corresponding internal service interface according to the internal service interface called by each internal service interface;
[0222] According to the number of calls and the business weight of each internal service interface corresponding to each business process node, the business proportion of the corresponding business process node is obtained.
[0223] Preferably, the second determining unit 703 is used for:
[0224] For each internal service interface, perform the following steps:
[0225] If it is determined that an internal service interface does not call an external service interface, then the business weight of the internal service interface is determined to be a specified weight;
[0226] If it is determined that an internal service interface calls at least one external service interface, a business weight of an internal service interface is determined according to the at least one external service interface and a corresponding interface coefficient.
[0227] Preferably, the construction unit 704 is used for:
[0228] Get the database table information of the database;
[0229] Generate multiple database operation statements based on the business proportion of each business process node and database table information;
[0230] Execute each database operation statement and store the constructed test data in the database, where the proportion of each type of data in the test data is the business proportion.
[0231] In a method, device, equipment and medium for database testing provided by an embodiment of the present application, the business process source code of the target business object is parsed to obtain each business call path, and the corresponding business proportion is determined according to the number of calls of each internal service interface corresponding to each business process node in each business call path, and test data is constructed according to the business proportion, and then the database of the business product is tested according to the test data to obtain the test result. In this way, the problem of being unable to accurately test the database before the business product is launched is solved, and the stability of the database after the business product is launched is improved.
[0232] Figure 8 FIG. 8 is a schematic diagram showing a structure of a control device 8000. Figure 8 As shown, the control device 8000 includes: a processor 8010, a memory 8020, a power supply 8030, a display unit 8040, and an input unit 8050.
[0233] Processor 8010 is the control center of control device 8000. It connects various components using various interfaces and lines, and performs various functions of control device 8000 by running or executing software programs and / or data stored in memory 8020, thereby monitoring control device 8000 as a whole.
[0234] In the embodiment of the present application, when the processor 8010 calls the computer program stored in the memory 8020, the following is executed: Figure 2 The embodiment shown in provides a method for database testing.
[0235] Optionally, the processor 8010 may include one or more processing units; preferably, the processor 8010 may integrate an application processor and a modem processor, wherein the application processor mainly processes an operating system, a user interface, and applications, and the modem processor mainly processes wireless communications. It is understandable that the modem processor may not be integrated into the processor 8010. In some embodiments, the processor and the memory may be implemented on a single chip, and in some embodiments, they may also be implemented separately on separate chips.
[0236] The memory 8020 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, various applications, etc.; the data storage area may store data created according to the use of the control device 8000, etc. In addition, the memory 8020 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices, etc.
[0237] The control device 8000 also includes a power supply 8030 (such as a battery) for supplying power to each component. The power supply can be logically connected to the processor 8010 through a power management system, thereby managing functions such as charging, discharging, and power consumption through the power management system.
[0238] The display unit 8040 may be used to display information input by the user or information provided to the user and various menus of the control device 8000, and in the embodiment of the present invention, is mainly used to display the display interface of each application in the control device 8000 and objects such as text and pictures displayed in the display interface. The display unit 8040 may include a display panel 8041. The display panel 8041 may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc.
[0239] The input unit 8050 may be used to receive information such as numbers or characters input by the user. The input unit 8050 may include a touch panel 8051 and other input devices 8052. The touch panel 8051, also known as a touch screen, may collect user touch operations on or near it (such as operations performed by the user using a finger, a stylus, or any other suitable object or accessory on or near the touch panel 8051).
[0240] Specifically, the touch panel 8051 can detect the user's touch operation, detect the signal brought by the touch operation, convert these signals into touch point coordinates, send them to the processor 8010, and receive and execute the command sent by the processor 8010. In addition, the touch panel 8051 can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic wave. Other input devices 8052 can include but are not limited to one or more of a physical keyboard, function keys (such as volume control keys, power on / off keys, etc.), a trackball, a mouse, a joystick, etc.
[0241] Of course, the touch panel 8051 can cover the display panel 8041. When the touch panel 8051 detects a touch operation on or near it, it transmits it to the processor 8010 to determine the type of touch event, and then the processor 8010 provides corresponding visual output on the display panel 8041 according to the type of touch event. Figure 8 In the embodiment, the touch panel 8051 and the display panel 8041 are used as two independent components to realize the input and output functions of the control device 8000, but in some embodiments, the touch panel 8051 and the display panel 8041 can be integrated to realize the input and output functions of the control device 8000.
[0242] The control device 8000 may also include one or more sensors, such as a pressure sensor, a gravity acceleration sensor, a proximity light sensor, etc. Of course, according to the needs of specific applications, the control device 8000 may also include other components such as a camera. Since these components are not the key components used in the embodiments of the present application, Figure 8 It is not shown and will not be described in detail.
[0243] Those skilled in the art will understand that Figure 8 This is merely an example of a control device and does not constitute a limitation on the control device. The control device may include more or fewer components than shown in the figure, or a combination of certain components, or different components.
[0244] It can be understood by those skilled in the art that all or part of the steps of the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above method embodiment are executed; and the aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, read-only memory (ROM), random access memory (RAM), magnetic disks or optical disks. Alternatively, if the above integrated unit of the present invention is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the embodiment of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in each embodiment of the present invention. And the aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROM, RAM, magnetic disks or optical disks.
[0245] The embodiment of the present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. The processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the control method of the database test in any of the above method embodiments.
[0246] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a control device (which can be a personal computer, a server, or a network device, etc.) to execute the methods of each embodiment or some parts of the embodiment.
[0247] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for database testing, characterized in that: include: Parsing the business process source code of the target business object, and obtaining at least one business call path based on the parsing result, wherein the business call path is composed of business process nodes and internal service interfaces between the business process nodes; Determine, according to the at least one business call path, the number of times each internal service interface corresponding to each business process node is called; Determine the business proportion of each business process node according to the number of calls of each internal service interface corresponding to each business process node; Construct corresponding test data according to the business proportion of each business process node; According to the test data, the database corresponding to the target business object is tested to obtain a database test result; Among them, constructing corresponding test data according to the business proportion of each business process node is performed through the following steps: Obtaining database table information of the database; Generate multiple database operation statements according to the business proportion of each business process node and the database table information; Execute each database operation statement, and store the constructed test data in the database, wherein the proportion of each type of data in the test data is the business proportion.
2. The method according to claim 1, characterized in that Parsing the business process source code of the target business object and obtaining at least one business call path based on the parsing result includes: Parsing the business process source code to obtain a parsing result; Based on the analysis result, determining each business process node set in the business process source code and the internal service interface called between each business process node; Generate a business process diagram based on each business process node and the internal service interface called between each business process node; According to the business process diagram, determining a starting node and at least one ending node in each business process node; Determine a service call path corresponding to the service flow diagram according to the starting node and the at least one terminating node; A business call path includes: business process nodes between a start node and an end node, and internal service interfaces called between the business process nodes.
3. The method according to claim 2, characterized in that Generate a business process diagram based on each business process node and the internal service interface called between each business process node, including: Obtain the state machine according to each business process node and the internal service interface called between each business process node; The state machine is subjected to image conversion processing to obtain a corresponding business process diagram.
4. The method according to claim 1, characterized in that Determining the number of times each internal service interface corresponding to each business process node is called according to the at least one business call path, including: For each business process node except the start node, perform the following steps: From the at least one business call path, extract at least one local call path corresponding to a business process node, each local call path including: a business process node between a start node and the business process node, and an internal service interface called between each business process node; Determine the internal service interface in the at least one local call path as the internal service interface corresponding to the one business process node; The number of times each internal service interface corresponding to the one business process node is called by the at least one local call path is determined as the corresponding number of times called.
5. The method according to any one of claims 1 to 4, characterized in that: According to the number of calls of each internal service interface corresponding to each business process node, the business proportion of each business process node is determined respectively, including: Determine the internal service interface called by each internal service interface according to the analysis result; Determine the business weight of the corresponding internal service interface according to the internal service interface called by each internal service interface; According to the number of calls and the business weight of each internal service interface corresponding to each business process node, the business proportion of the corresponding business process node is obtained.
6. The method according to claim 5, characterized in that According to the internal service interface called by each internal service interface, the business weight of the corresponding internal service interface is determined, including: For each internal service interface, perform the following steps: If it is determined that an internal service interface does not call an external service interface, determining that the service weight of the internal service interface is a specified weight; If it is determined that the one internal service interface calls at least one external service interface, the business weight of the one internal service interface is determined according to the at least one external service interface and a corresponding interface coefficient.
7. A database testing device, characterized in that: include: A parsing unit, configured to parse the business process source code of the target business object, and obtain at least one business call path based on the parsing result, wherein the business call path is composed of business process nodes and internal service interfaces between the business process nodes; A first determining unit, configured to determine, according to the at least one business call path, the number of times each internal service interface corresponding to each business process node is called; The second determining unit is used to determine the business proportion of each business process node according to the number of times each internal service interface corresponding to each business process node is called; A construction unit, used to construct corresponding test data according to the business proportion of each business process node; A testing unit, configured to test the database corresponding to the target business object according to the test data to obtain a database test result; Among them, when the construction unit constructs corresponding test data according to the business proportion of each business process node, it is specifically used to: obtain database table information of the database; generate multiple database operation statements according to the business proportion of each business process node and the database table information; execute each database operation statement and store the constructed test data in the database, wherein the proportion of each type of data in the test data is the business proportion.
8. A control 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, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Method and apparatus for testing an application
CN109426609A
Test method, test device and computer readable storage medium
CN110134587A
