CN113238929B - Code testing method and device based on Mock data, electronic equipment and storage medium - Google Patents

Code testing method and device based on Mock data, electronic equipment and storage medium Download PDF

Info

Publication number
CN113238929B
CN113238929B CN202110450574.9A CN202110450574A CN113238929B CN 113238929 B CN113238929 B CN 113238929B CN 202110450574 A CN202110450574 A CN 202110450574A CN 113238929 B CN113238929 B CN 113238929B
Authority
CN
China
Prior art keywords
data
mock
packet
code
code packet
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.)
Active
Application number
CN202110450574.9A
Other languages
Chinese (zh)
Other versions
CN113238929A (en
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.)
Ping An Puhui Enterprise Management Co Ltd
Original Assignee
Ping An Puhui Enterprise Management 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 Ping An Puhui Enterprise Management Co Ltd filed Critical Ping An Puhui Enterprise Management Co Ltd
Priority to CN202110450574.9A priority Critical patent/CN113238929B/en
Publication of CN113238929A publication Critical patent/CN113238929A/en
Application granted granted Critical
Publication of CN113238929B publication Critical patent/CN113238929B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention relates to a data testing technology, and discloses a code testing method based on Mock data, which comprises the following steps: receiving a development code packet and a test code packet input by a user, generating a Mock connection packet by using a logic code packet input by the user when the development code packet passes the operation, analyzing the data connection type of the Mock connection packet, extracting Mock data from a storage space corresponding to the data connection type, combining the Mock data and the test code packet to obtain a test code packet to be operated, operating the test code packet to be operated, and calling the Mock data to execute a code test. The invention also discloses a code testing device based on the Mock data, electronic equipment and a storage medium. The invention can solve the problems of strong dependence between the test code packet and the development code packet and interface access congestion of the Mock data generator.

Description

Code testing method and device based on Mock data, electronic equipment and storage medium
Technical Field
The invention relates to the field of data testing, in particular to a code testing method and device based on Mock data, electronic equipment and a computer readable storage medium.
Background
The code test is an essential loop in program operation and online, but data needs to be acquired in the code test process, and particularly when various types of data are acquired, a stable external data source interface needs to be called.
However, at present, the stability of an external data source interface is poor, a small part of schemes use Mock data to realize data acquisition, the Mock data is created in a form of a virtual object (Mock object) for some data which is not easy to construct or to obtain, so that the data can be called during software testing, but in the current commonly used Mock data code testing scheme, a test code packet and a development code packet are directly packaged and compiled, and an open source generator Mock. js for generating the Mock data is directly called after the compilation is passed, although the method can complete code testing, because the test code packet and the development code packet are packaged and compiled together, the test code packet and the development code packet generate strong dependence relation, if a user needs to send and change, the test code packet and the development code packet need to be recompiled and compiled again, resources are consumed, in addition, the interface of the Mock data generator which is opened is directly called, the interface of the Mock data generator needs to be repeatedly accessed, the problem of interface access congestion easily occurs.
Disclosure of Invention
The invention provides a code testing method and device based on Mock data, electronic equipment and a computer readable storage medium, and mainly aims to solve the problems of strong dependency relationship between a test code packet and a development code packet and interface access congestion of a Mock data generator.
In order to achieve the above object, the code testing method based on Mock data provided by the present invention comprises:
receiving a development code packet and a test code packet input by a user, and generating a Mock connection packet by using a logic code packet input by the user when the development code packet passes the operation;
analyzing the data connection type of the Mock connection packet, and extracting Mock data from a storage space corresponding to the data connection type;
combining the Mock data and the test code packet to obtain a test code packet to be operated;
and running the test code packet to be run, and calling the Mock data to execute code testing.
Optionally, before the combining the Mock data and the test code packet, the method includes:
analyzing the field type of the Mock data, and splitting the Mock data into field data sets of different field types according to the field type;
building a gateway verification program corresponding to the field data sets, and respectively verifying the corresponding field data sets by using the gateway verification program;
and when all the field data sets pass the verification, combining the Mock data and the test code packet.
Optionally, the constructing a gateway verification program corresponding to the field data set includes:
receiving a verification script constructed by a user according to the field data set;
and generating the gateway verification program by using the verification script and the field data set.
Optionally, the generating the gateway verification program by using the verification script and the field data set includes:
extracting input parameters of each function in the verification script from the verification script;
splitting the field data set according to the input parameters to obtain a field parameter set;
and combining the field parameter set to the check script to generate the gateway check program.
Optionally, the analyzing the data connection type of the Mock connection packet, and extracting Mock data from a storage space corresponding to the data connection type includes:
generating a Mock configuration file by using a data calling instruction input by a user;
judging the data connection type of the Mock connection packet by using the Mock configuration file;
when the data connection type of the Mock connection packet is a local data connection type, extracting the Mock data from a local disk;
and when the Mock connection packet data connection type is a database connection type, extracting the Mock data from a pre-constructed Mock database.
Optionally, the running of the development code package includes:
generating the same ID identification according to the development code packet and the test code packet;
injecting the development code packet into a pre-constructed Spring container by using the ID identification;
compiling the development code package in the Spring container, judging whether the development code package is compiled successfully or not, re-receiving the development code package input by a user if the development code package is not compiled successfully, and running the development code package if the development code package is compiled successfully.
Optionally, the combining the Mock data and the test code packet to obtain a test code packet to be run includes:
packaging the Mock data into a data calling interface;
and distributing the ID identification to the test code packet, and taking the URL of the data call interface as a function parameter of the test code packet to obtain the test code packet to be operated.
In order to solve the above problem, the present invention further provides a code testing apparatus based on Mock data, the apparatus comprising:
the connection package generation module is used for receiving a development code package and a test code package input by a user and generating a Mock connection package by using a logic code package input by the user when the development code package passes the operation;
the Mock data extraction module is used for analyzing the data connection type of the Mock connection packet and extracting Mock data from the storage space corresponding to the data connection type;
the test code packet generating module is used for combining the Mock data and the test code packet to obtain a test code packet to be operated;
and the test code packet running module is used for running the test code packet to be run and calling the Mock data to execute code testing.
In order to solve the above problem, the present invention also provides an electronic device, including:
a memory storing at least one instruction; and
and the processor executes the instructions stored in the memory to realize the code testing method based on Mock data.
In order to solve the above problem, the present invention further provides a computer-readable storage medium including a storage data area and a storage program area, the storage data area storing created data, the storage program area storing a computer program; wherein the computer program, when executed by a processor, implements the Mock data based code testing method described in any of the above.
According to the embodiment of the invention, after the development code packet and the test code packet are received, the development code packet and the test code packet are not directly packed and compiled, but the development code packet is firstly operated, after the development code packet passes the operation, the Mock connection packet is generated by utilizing the logic code packet input by the user, and the Mock data is extracted from the corresponding storage space according to the data connection type of the Mock connection packet The device and the computer readable storage medium can solve the problems of strong dependency relationship between the test code packet and the development code packet and interface access congestion of the Mock data generator.
Drawings
FIG. 1 is an internal structure diagram of a code testing platform based on Mock data according to an embodiment of the present invention;
FIG. 2 is a data interaction diagram of a code testing method based on Mock data according to an embodiment of the present invention;
FIG. 3 is a schematic flowchart of a code testing method based on Mock data according to an embodiment of the present invention;
FIG. 4 is a block diagram of a code testing apparatus based on Mock data according to an embodiment of the present invention;
fig. 5 is a schematic diagram of an internal structure of an electronic device implementing a code testing method based on Mock data according to an embodiment of the present invention;
the implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The embodiment of the application provides a code testing method based on Mock data, and an execution subject of the code testing method based on Mock data includes but is not limited to at least one of electronic equipment such as a server and a terminal, which can be configured to execute the method provided by the embodiment of the application. In other words, the code testing method based on Mock data may be executed by software or hardware installed in a terminal device or a server device, and the software may be a block chain platform. The server includes but is not limited to: a single server, a server cluster, a cloud server or a cloud server cluster, and the like.
In an embodiment of the present invention, the code testing method based on Mock data is applied to a code testing platform, and is shown in fig. 1, which is an internal structure schematic diagram of the code testing platform, and the code testing platform 1 includes a software package receiver 2, a development container 3, a local disk 4, and a Mock database 5.
The software package receiver 2 is an interface developed by the code testing platform 1 for the purpose of facing users, and can receive a development code package, a test code package and a data call instruction input by a user.
The development container 3 is an open source application program framework, and is mainly used for realizing data calling according to a development code packet and a data calling instruction received by the software packet receiver 2;
the local disk 4 is a hard disk device which stores different analog data in advance; the Mock database 5 is constructed based on mock.js, wherein the mock.js is an open-source simulation data generator and can generate corresponding simulation data in real time according to the requirements of users on different data types.
Further, the software package receiver 2 receives a development code package and a data call instruction, and triggers data call, and the local disk 4 and the Mock database 5 provide support for simulation data in real time when the development container 3 executes data call, so as to assist the development container 3 in realizing data call. Therefore, the software package receiver 2, the development container 3, the local disk 4 and the Mock database 5 are matched with one another in a cooperative manner, and the code testing method based on Mock data is realized.
Referring to fig. 2, a data interaction diagram of the code testing platform and a user when the code testing method based on Mock data is executed according to the embodiment of the present invention is shown, wherein the software package receiver 2, the development container 3, the local disk 4, and the Mock database 5 mainly function as follows:
1. the software package receiver receives a development code package and a test code package input by a user, and generates a Mock connection package by using a logic code package input by the user when the development code package passes;
2. and the development container analyzes the data connection type of the Mock connection packet and extracts Mock data from the storage space corresponding to the data connection type. Further, if the Mock connection packet is of a local data connection type, executing step 3, and transmitting the Mock local data to the development container by the local disk;
if the Mock connection packet is of a database connection type, executing step 4, and transmitting the Mock database data to the development container by the Mock database;
5. combining the Mock data and the test code packet to obtain a test code packet to be operated;
6. and the development container runs the test code packet to be run and calls the Mock data to execute code test.
Fig. 3 is a schematic flow chart of a code testing method based on Mock data according to another embodiment of the present invention. In this embodiment, the code testing method based on Mock data includes:
and S1, receiving the development code packet and the test code packet input by the user, and generating a Mock connection packet by using the logic code packet input by the user when the development code packet passes.
In the embodiment of the invention, the code testing method based on the Mock data can be applied to front-end development, for example, the data of the back-end interface needs to be called in the front-end development process, and when the conditions of insufficient quantity of the back-end interface, speed limit of the back-end interface and the like occur, abnormal events that the data cannot be provided by the back-end interface in a short time are easily caused, so in order to solve the problem that the back-end interface is excessively depended on, the Mock data (also called analog data and virtual data) is generated and directly called to meet the data calling requirement of the front-end development.
In detail, the development code package is a project code developed based on different projects, such as a front-end page code package developed based on the above front-end development, including a project code of a student information management system, a project code of a shopping site, and the like. In the embodiment of the invention, the development code package corresponds to a test code package, for example, project codes based on a development financial risk management system, and before formal operation, the corresponding test code package is required to be used for testing the abnormity of the development code package, so that the operation of the subsequent development code package is ensured to be correct.
Further, the running of the development code package comprises:
generating the same ID identification according to the development code package and the test code package, injecting the development code package into a pre-constructed Spring container by using the ID identification, compiling the development code package in the Spring container, judging whether the development code package is compiled to pass or not, re-receiving the development code package input by a user if the development code package is not compiled to pass, and running the development code package if the development code package is compiled to pass.
Further, the compiling refers to translating a code package written in a high level programming language into a translation program in a machine language format understandable by a computer. The high-level programming language includes JAVA, C + +, etc., and the translator includes assembly language, etc.
Further, in an implementation of the present invention, the compiling the development code package in the Spring container includes:
and distributing the ID identification to the development code package by using the Spring container, and compiling the development code package when the distribution is successful.
The Spring container is a management system of a programming object, and in order to realize absolute separation of a development code package and a test code package and prevent a strong dependency relationship from being generated during data testing, in the embodiment of the invention, the development code package and the test code package are respectively executed in different stages in the Spring container.
Compared with the traditional scheme of packaging and merging the development code packet and the test code packet and then compiling at the same time, the scheme is easy to send the problem that the development code packet and the test code packet are excessively coupled in the whole code testing process, so in the embodiment of the invention, the development code packet and the test code packet are compiled separately by using the ID (identity) identifier, for example, the ID identifier of 763 is allocated to the development code packet and the test code packet, when the development code packet needs to be compiled, 763 is allocated to the development code packet, and the code integrity of the test code packet is kept until the development code packet is compiled.
In detail, after the development code package runs through, the generating a Mock connection package by using the logic code package input by the user includes:
receiving a data calling instruction input by a user and the logic code packet, generating a Mock configuration file according to the data calling instruction, and connecting the logic code packet by using the Mock configuration file;
and if the connection is successful, generating the Mock connection packet by using the Mock configuration file and the logic code packet.
In detail, the data call instruction is an instruction sent by the user according to the project requirement, and when the project code of the financial risk management system is tested as described above, the user sends the data call instruction to call a plurality of test data so as to meet the test requirement of the financial risk management system.
The logic code packet is also called JAR code packet, and is a code block written by a user in advance according to a certain programming language, wherein the logic code packet mainly relates to the data type of Mock data to be called by the user, such as Json, Map, Xml and other data types.
The Mock configuration file is a correspondingly written configuration information file according to different application scenes of the embodiment of the invention, such as the version number, the network IP address and the like of a system depended on by the embodiment of the invention, and when a data call instruction is received, the embodiment of the invention can automatically acquire the pre-stored Mock configuration file from a database.
The Mock connection package is a program package capable of automatically connecting mock.js, wherein the mock.js is an open-source Mock data generator and can generate corresponding Mock data in real time according to the requirements of users on different data types. For example, when testing a financial risk management system, different types of Mock data need to be acquired, a Mock connection package named ap-Mock. apermock. log. show ═ true (recommended value); apermock connection mode: local reading, database mode and http network connection acquisition; whether Apermock linked databases support mysql, oracle, mongo.
S2, analyzing the data connection type of the Mock connection packet, and extracting Mock data from the storage space corresponding to the data connection type.
In detail, the S2 includes:
judging the data connection type of the Mock connection packet by using the Mock configuration file;
when the data connection type of the Mock connection packet is a local data connection type, extracting the Mock data from a local disk;
and when the Mock connection packet data connection type is a database connection type, extracting the Mock data from a pre-constructed Mock database.
In the embodiment of the invention, the connection type comprises a local data connection type and a database connection type, wherein the local data connection type indicates that Mock local data is obtained by simulating data types such as Json, Map, Xml and the like by using a local disk (including a local computer, a local server and the like) where a project is located. The Mock database is constructed based on mock.js, corresponding simulation data are generated in real time through the mock.js according to the requirements of users on different data types and are stored in the Mock database, and when the Mock connection packet is of a database connection type, the Mock database data are directly extracted from the Mock database.
And S3, combining the Mock data and the test code packet to obtain a test code packet to be operated.
In order to improve the security of combination with the Mock data, the embodiment of the invention needs to execute data verification operation on the Mock data.
In detail, before the combining the Mock data and the test code packet, the method includes:
analyzing the field type of the Mock data, and splitting the Mock data into field data sets of different field types according to the field type;
building a gateway verification program corresponding to the field data sets, and respectively verifying the corresponding field data sets by using the gateway verification program;
and when all the field data sets pass the verification, combining the Mock data and the test code packet.
In the embodiment of the invention, both the Mock database data and the Mock local data can comprise field types such as a character string type, an integer type, a long integer type, a double precision type, an array type, a Boolean type and the like, for example, a recommended button developed by a tester test developer is a character string field type, and after the button is clicked, whether the background database is successfully connected or not is determined, and whether the background database is successfully connected or not is determined as the Boolean type field type. Therefore, according to different field types, the Mock database data or the Mock local data can be divided into a string type field data set, a double-precision type field data set and the like.
After field data sets of different field types are obtained, the building of a gateway verification program corresponding to the field data sets comprises the following steps: receiving a verification script constructed by a user according to the field data set; and generating the gateway verification program by using the verification script and the field data set.
Further, the generating the gateway verification program by using the verification script and the field data set includes: extracting input parameters of each function in the verification script from the verification script; splitting the field data set according to the input parameters to obtain a field parameter set; and combining the field parameter set to the check script to generate the gateway check program.
For example, for a field data set of a character string type, a corresponding character string parameter length check program is constructed, for example, a gateway check program with the parameter length of a button character string not greater than 20 is constructed, and for a long and integral field data set, a gateway check program with the value not greater than a threshold value is constructed, and the like. In the embodiment of the invention, each field data set is used as the input of a corresponding gateway strong check program, the gateway strong check program is operated, the check operation on each field data set is executed, if the check is not passed, the Mock data does not meet the requirements of the user, and therefore, the result of the failed check needs to be fed back to the user for detection.
If the check passes, it indicates that the Mock data meets the user requirements, so a combination operation is executed, and in detail, the Mock data and the test code packet are combined to obtain a test code packet to be run, including:
packaging the Mock database data or the Mock local data into a data calling interface;
and distributing the ID identification to the test code packet, and when the distribution is successful, taking the URL of the data call interface as a function parameter of the test code packet to obtain the test code packet to be operated.
As described in S1, in order to prevent the problem that the code coupling between the test code package and the development code package is too serious, in the embodiment of the present invention, the test code package and the development code package are processed separately in different stages, and after the development code package is compiled successfully, the ID is assigned to the test code package, and the compiled development code package is kept complete until the test code package to be run is obtained.
And S6, running the test code packet to be run, and calling the Mock data to execute code testing.
According to the embodiment of the invention, after the development code packet and the test code packet are received, the development code packet and the test code packet are not directly packed and compiled, but the development code packet is firstly operated, after the development code packet passes the operation, the Mock connection packet is generated by utilizing the logic code packet input by the user, and the Mock data is extracted from the corresponding storage space according to the data connection type of the Mock connection packet The device and the computer readable storage medium can solve the problems of strong dependency relationship between the test code packet and the development code packet and interface access congestion of the Mock data generator.
Fig. 4 is a schematic block diagram of a code testing apparatus based on Mock data according to the present invention.
The code testing apparatus 100 based on Mock data according to the present invention can be installed in an electronic device. According to the realized functions, the code testing device based on Mock data may include a connection packet generation module 101, a Mock data extraction module 102, a test code packet generation module 103, and a test code packet operation module 104. A module according to the present invention, which may also be referred to as a unit, refers to a series of computer program segments that can be executed by a processor of an electronic device and can perform a fixed function, and are stored in a memory of the electronic device.
In the present embodiment, the functions regarding the respective modules/units are as follows:
the connection packet generation module 101 is configured to receive a development code packet and a test code packet input by a user, and generate a Mock connection packet by using a logic code packet input by the user when the development code packet passes through operation;
the Mock data extraction module 102 is configured to analyze a data connection type of the Mock connection packet, and extract Mock data from a storage space corresponding to the data connection type;
the test code packet generating module 103 is configured to combine the Mock data and the test code packet to obtain a test code packet to be run;
the test code packet running module 104 is configured to run the test code packet to be run, and call the Mock data to execute a code test.
Each module in the code testing device 100 based on Mock data provided by the embodiment of the present invention can use the same means as the code testing method based on Mock data, and the specific implementation steps are not described herein again, and the technical effect generated by the functions of each module/unit is the same as that of the code testing method based on Mock data, that is, the problems of strong dependency between the test code packet and the development code packet and interface access congestion of the Mock data generator are solved.
Fig. 5 is a schematic structural diagram of an electronic device implementing a code testing method based on Mock data according to the present invention.
The electronic device 1 may comprise a processor 10, a memory 11 and a bus, and may further comprise a computer program, such as a test data invocation program 12, stored in the memory 11 and executable on the processor 10.
The memory 11 includes at least one type of readable storage medium, which includes flash memory, removable hard disk, multimedia card, card-type memory (e.g., SD or DX memory, etc.), magnetic memory, magnetic disk, optical disk, etc. The memory 11 may in some embodiments be an internal storage unit of the electronic device 1, such as a removable hard disk of the electronic device 1. The memory 11 may also be an external storage device of the electronic device 1 in other embodiments, such as a plug-in mobile hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the electronic device 1. Further, the memory 11 may also include both an internal storage unit and an external storage device of the electronic device 1. The memory 11 may be used not only to store application software installed in the electronic device 1 and various types of data, such as code of the test data calling program 12, but also to temporarily store data that has been output or is to be output.
The processor 10 may be composed of an integrated circuit in some embodiments, for example, a single packaged integrated circuit, or may be composed of a plurality of integrated circuits packaged with the same or different functions, including one or more Central Processing Units (CPUs), microprocessors, digital Processing chips, graphics processors, and combinations of various control chips. The processor 10 is a Control Unit (Control Unit) of the electronic device, connects various components of the electronic device by using various interfaces and lines, and executes various functions and processes data of the electronic device 1 by running or executing programs or modules (e.g., executing a test data calling program, etc.) stored in the memory 11 and calling data stored in the memory 11.
The bus 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. The bus is arranged to enable connection communication between the memory 11 and at least one processor 10 or the like.
Fig. 5 only shows an electronic device with components, and it will be understood by a person skilled in the art that the structure shown in fig. 5 does not constitute a limitation of the electronic device 1, and may comprise fewer or more components than shown, or a combination of certain components, or a different arrangement of components.
For example, although not shown, the electronic device 1 may further include a power supply (such as a battery) for supplying power to each component, and preferably, the power supply may be logically connected to the at least one processor 10 through a power management device, so as to implement functions of charge management, discharge management, power consumption management, and the like through the power management device. The power supply may also include any component of one or more dc or ac power sources, recharging devices, power failure detection circuitry, power converters or inverters, power status indicators, and the like. The electronic device 1 may further include various sensors, a bluetooth module, a Wi-Fi module, and the like, which are not described herein again.
Further, the electronic device 1 may further include a network interface, and optionally, the network interface may include a wired interface and/or a wireless interface (such as a WI-FI interface, a bluetooth interface, etc.), which are generally used to establish a communication connection between the electronic device 1 and another electronic device.
Optionally, the electronic device 1 may further comprise a user interface, which may be a Display (Display), an input unit (such as a Keyboard), and optionally a standard wired interface, a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, or the like. The display, which may also be referred to as a display screen or display unit, is suitable for displaying information processed in the electronic device 1 and for displaying a visualized user interface, among other things.
It is to be understood that the described embodiments are for purposes of illustration only and that the scope of the appended claims is not limited to such structures.
The memory 11 in the electronic device 1 stores a test data calling program 12 which is a combination of instructions that, when executed in the processor 10, implement:
receiving a development code packet and a test code packet input by a user, and generating a Mock connection packet by using a logic code packet input by the user when the development code packet passes the operation;
analyzing the data connection type of the Mock connection packet, and extracting Mock data from a storage space corresponding to the data connection type;
combining the Mock data and the test code packet to obtain a test code packet to be operated;
and running the test code packet to be run, and calling the Mock data to execute code testing.
Further, the integrated modules/units of the electronic device 1, if implemented in the form of software functional units and sold or used as separate products, may be stored in a computer readable storage medium. The computer-readable medium may include: any entity or device capable of carrying said computer program code, recording medium, U-disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM).
Further, the computer usable storage medium may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function, and the like; the storage data area may store data created according to the use of the blockchain node, and the like.
The present invention also provides a computer-readable storage medium, storing a computer program which, when executed by a processor of an electronic device, may implement:
receiving a development code packet and a test code packet input by a user, and generating a Mock connection packet by using a logic code packet input by the user when the development code packet passes the operation;
analyzing the data connection type of the Mock connection packet, and extracting Mock data from a storage space corresponding to the data connection type;
combining the Mock data and the test code packet to obtain a test code packet to be operated;
and running the test code packet to be run, and calling the Mock data to execute code testing.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus, device and method can be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is only one logical functional division, and other divisions may be realized in practice.
The modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical units, may be located in one position, or may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
In addition, functional modules in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional module.
It will be evident to those skilled in the art that the invention is not limited to the details of the foregoing illustrative embodiments, and that the present invention may be embodied in other specific forms without departing from the spirit or essential attributes thereof.
The present embodiments are therefore to be considered in all respects as illustrative and not restrictive, the scope of the invention being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any accompanying claims should not be construed as limiting the claim concerned.
The block chain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism, an encryption algorithm and the like. A block chain (Blockchain), which is essentially a decentralized database, is a string of data blocks associated by using a cryptographic method, and each data block contains information of a batch of network transactions, which is used for verifying the validity (anti-counterfeiting) of the information and generating a next block. The blockchain may include a blockchain underlying platform, a platform product service layer, an application service layer, and the like.
Furthermore, it is obvious that the word "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. A plurality of units or means recited in the system claims may also be implemented by one unit or means in software or hardware. The terms second, etc. are used to denote names, but not any particular order.
Finally, it should be noted that the above embodiments are only intended to illustrate the technical solutions of the present invention and not to limit the same, and although the present invention is described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.

Claims (8)

1. A code testing method based on Mock data is characterized by comprising the following steps:
receiving a development code packet and a test code packet input by a user, generating the same ID (identity) according to the development code packet and the test code packet, injecting the development code packet into a pre-constructed Spring container by using the ID, compiling the development code packet in the Spring container, judging whether the development code packet is compiled to pass or not, re-receiving the development code packet input by the user if the development code packet is not compiled to pass, and generating a Mock connection packet by using a logic code packet input by the user when the development code packet runs to pass if the development code packet is compiled to pass;
generating a Mock configuration file by using a data calling instruction input by a user, judging the data connection type of the Mock connection packet by using the Mock configuration file, extracting the Mock data from a local disk when the data connection type of the Mock connection packet is a local data connection type, and extracting the Mock data from a pre-constructed Mock database when the data connection type of the Mock connection packet is a database connection type;
combining the Mock data and the test code packet to obtain a test code packet to be operated;
and running the test code packet to be run, and calling the Mock data to execute the code test.
2. The Mock data based code testing method according to claim 1, wherein prior to said combining said Mock data with said test code packet, said method comprises:
analyzing the field type of the Mock data, and splitting the Mock data into field data sets of different field types according to the field type;
building a gateway verification program corresponding to the field data sets, and respectively verifying the corresponding field data sets by using the gateway verification program;
and when all the field data sets pass the verification, combining the Mock data and the test code packet.
3. The Mock data-based code testing method according to claim 2, wherein said constructing a gateway verification program corresponding to said field data set comprises:
receiving a verification script constructed by a user according to the field data set;
and generating the gateway verification program by using the verification script and the field data set.
4. The Mock data-based code testing method according to claim 3, wherein the generating of the gateway verification program using the verification script and the field data set comprises:
extracting input parameters of each function in the verification script from the verification script;
splitting the field data set according to the input parameters to obtain a field parameter set;
and combining the field parameter set to the check script to generate the gateway check program.
5. The Mock data-based code testing method according to claim 1, wherein the step of combining the Mock data with the test code packet to obtain a test code packet to be run comprises the steps of:
packaging the Mock data into a data calling interface;
and distributing the ID identification to the test code packet, and taking the URL of the data call interface as a function parameter of the test code packet to obtain the test code packet to be operated.
6. A code testing apparatus based on Mock data, the apparatus comprising:
the connection package generation module is used for receiving a development code package and a test code package input by a user, generating the same ID identification according to the development code package and the test code package, injecting the development code package into a pre-constructed Spring container by using the ID identification, compiling the development code package in the Spring container, judging whether the development code package is compiled to pass or not, re-receiving the development code package input by the user if the development code package is not compiled to pass, and generating a Mock connection package by using a logic code package input by the user when the development code package is operated to pass if the development code package is compiled to pass;
the system comprises a Mock data extraction module, a Mock configuration module and a Mock data storage module, wherein the Mock data extraction module is used for generating a Mock configuration file by using a data calling instruction input by a user, judging the data connection type of a Mock connection packet by using the Mock configuration file, extracting the Mock data from a local disk when the data connection type of the Mock connection packet is a local data connection type, and extracting the Mock data from a pre-constructed Mock database when the data connection type of the Mock connection packet is a database connection type;
the test code packet generating module is used for combining the Mock data and the test code packet to obtain a test code packet to be operated;
and the test code packet running module is used for running the test code packet to be run and calling the Mock data to execute code testing.
7. An electronic device, characterized in that the electronic device comprises:
at least one processor; and (c) a second step of,
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the Mock data based code testing method of any of claims 1 to 5.
8. A computer-readable storage medium comprising a storage data area and a storage program area, wherein the storage data area stores created data, and the storage program area stores a computer program; wherein the computer program when executed by a processor implements the Mock data based code testing method according to any of claims 1 to 5.
CN202110450574.9A 2021-04-25 2021-04-25 Code testing method and device based on Mock data, electronic equipment and storage medium Active CN113238929B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110450574.9A CN113238929B (en) 2021-04-25 2021-04-25 Code testing method and device based on Mock data, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110450574.9A CN113238929B (en) 2021-04-25 2021-04-25 Code testing method and device based on Mock data, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN113238929A CN113238929A (en) 2021-08-10
CN113238929B true CN113238929B (en) 2022-09-27

Family

ID=77129229

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110450574.9A Active CN113238929B (en) 2021-04-25 2021-04-25 Code testing method and device based on Mock data, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113238929B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113778888B (en) * 2021-09-16 2024-05-17 平安银行股份有限公司 Code automatic test method, system, equipment and storage medium
CN114006885A (en) * 2021-11-17 2022-02-01 印象(山东)大数据有限公司 Data acquisition method and device based on intelligent equipment and electronic equipment
CN114826899B (en) * 2022-03-16 2024-01-23 青岛海尔科技有限公司 Debugging method and device for equipment control service, storage medium and electronic device

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2012092325A1 (en) * 2010-12-30 2012-07-05 Verisign, Inc. Method and system for implementing business logic
CN107368405A (en) * 2016-05-11 2017-11-21 腾讯科技(北京)有限公司 Test system, method of testing, mock platforms, blocker and client

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8627296B1 (en) * 2010-09-15 2014-01-07 Google Inc. Unified unit and integration test with automatic mock creation
CN110716919A (en) * 2019-09-23 2020-01-21 贝壳技术有限公司 Mock testing method, Mock testing device and storage medium
CN112187585B (en) * 2020-09-30 2023-10-27 腾讯科技(深圳)有限公司 Network protocol testing method and device

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2012092325A1 (en) * 2010-12-30 2012-07-05 Verisign, Inc. Method and system for implementing business logic
CN107368405A (en) * 2016-05-11 2017-11-21 腾讯科技(北京)有限公司 Test system, method of testing, mock platforms, blocker and client

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
基于NodeJS进行自动化单元测试中mock平台的设计与研究;潘诗瑶;《中国优秀硕士学位论文全文数据库 (信息科技辑)》;20180315(第03期);I138-852 *

Also Published As

Publication number Publication date
CN113238929A (en) 2021-08-10

Similar Documents

Publication Publication Date Title
CN113238929B (en) Code testing method and device based on Mock data, electronic equipment and storage medium
CN112506779A (en) Software interface testing method and device, electronic equipment and storage medium
CN113377661A (en) Interface testing method and device, electronic equipment and storage medium
CN113485685A (en) API interface creating method and device, electronic equipment and medium
CN113806434A (en) Big data processing method, device, equipment and medium
CN114385497A (en) Test environment generation method and device, electronic equipment and storage medium
CN114398282A (en) Test script generation method, device, equipment and storage medium
CN112579475A (en) Code testing method, device, equipment and readable storage medium
CN112579452A (en) Software automation test method, device, equipment and storage medium
CN114816371B (en) Message processing method, device, equipment and medium
CN115033489A (en) Code resource detection method and device, electronic equipment and storage medium
CN115080899A (en) Interactive sub-web page starting method, device, equipment and storage medium
CN114896164A (en) Interface optimization method and device, electronic equipment and storage medium
CN114489861A (en) Target component conversion method and device, electronic equipment and readable storage medium
CN114356379A (en) Backup-based service upgrading method, device, equipment and storage medium
CN114461531A (en) Platform adaptability test method, device, equipment and storage medium of test case
CN114721952A (en) Method, device, equipment and storage medium for synchronously deploying multiple sets of test environments
CN114020414A (en) Symbiotic method and device of Android system and bottom layer Linux, electronic equipment and storage medium
CN113051171A (en) Interface test method, device, equipment and storage medium
CN112667244A (en) Data verification method and device, electronic equipment and computer readable storage medium
CN112686759A (en) Account checking monitoring method, device, equipment and medium
CN114564413B (en) Synchronous equipment testing method and device
CN114416575A (en) Method, device and equipment for generating Mock data and storage medium
CN113032003B (en) Development file export method, development file export device, electronic equipment and computer storage medium
CN113704109B (en) Front-end and back-end data interaction method and device, electronic equipment and storage medium

Legal Events

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