CN112965905B - Data testing method, device, equipment and storage medium - Google Patents

Data testing method, device, equipment and storage medium Download PDF

Info

Publication number
CN112965905B
CN112965905B CN202110266657.2A CN202110266657A CN112965905B CN 112965905 B CN112965905 B CN 112965905B CN 202110266657 A CN202110266657 A CN 202110266657A CN 112965905 B CN112965905 B CN 112965905B
Authority
CN
China
Prior art keywords
test
database
data
script
code
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
CN202110266657.2A
Other languages
Chinese (zh)
Other versions
CN112965905A (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.)
Jingdong Technology Information Technology Co Ltd
Original Assignee
Jingdong Technology Information Technology 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 Jingdong Technology Information Technology Co Ltd filed Critical Jingdong Technology Information Technology Co Ltd
Priority to CN202110266657.2A priority Critical patent/CN112965905B/en
Publication of CN112965905A publication Critical patent/CN112965905A/en
Application granted granted Critical
Publication of CN112965905B publication Critical patent/CN112965905B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

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)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application relates to a data testing method, a device, equipment and a storage medium. The method comprises the steps of obtaining a test case corresponding to a code to be tested, wherein the test case is used for describing test logic for testing the code to be tested; acquiring test data in the test case, and writing the test data into a built-in database by utilizing a database script; executing the test case to obtain a test result obtained by accessing test data in the built-in database according to the test logic by the code to be tested. Since the test database is a built-in database in the electronic device, it can be ensured that the environment in the electronic device where the test is performed can access the built-in database.

Description

Data testing method, device, equipment and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a data testing method, apparatus, device, and storage medium.
Background
Unit testing refers to the process of verifying whether the code to be tested is correct during development. The unit test is an indispensable ring in the research and development system, and is the guarantee of correct execution of system logic.
In the related art, the unit test is performed on the code to be tested by using a test database outside the device, however, since the test database is located outside the device, it cannot be ensured that the environment in which the device performs the unit test can access the external test database.
Disclosure of Invention
The application provides a data testing method, a device, equipment and a storage medium, which are used for solving the problem that an external testing database cannot be accessed by an environment for testing an execution unit of equipment due to dependence on the external testing database.
In a first aspect, a data testing method is provided, including:
acquiring a test case corresponding to a code to be tested, wherein the test case is used for describing test logic for testing the code to be tested;
acquiring test data in the test case, and writing the test data into a built-in database by utilizing a database script;
and executing the test case to obtain a test result obtained by accessing the test data in the built-in database according to the test logic by the code to be tested.
Optionally, the writing the test data to the built-in database by using the database script includes:
Acquiring a database execution script in the database script and a database mode script matched with the database execution script; the database mode script comprises a data structure corresponding to newly added data or modified data in a software project to which a code to be tested belongs, and the data structure is used for identifying the attribute of test data;
acquiring a data structure corresponding to the test data from the database mode script;
And executing a script by using the database, and writing the test data into the built-in database according to the data structure.
Optionally, obtaining a database schema script matched with the database execution script includes:
acquiring a script identification of the database mode script, wherein the script identification is related to the data structure;
And when the script corresponding to the script identification exists in the database script, determining the script corresponding to the script identification as the database mode script.
Optionally, executing the test case to obtain a test result obtained by accessing the test data in the built-in database according to the test logic by the code to be tested, including:
Acquiring a method test case corresponding to a preset data method from the test cases, wherein the preset data method is any data method in the code to be tested, and the method test case is used for describing method test logic of the preset data method;
And obtaining the preset data method, testing logic according to the method, accessing the method test result obtained by the test data in the built-in database, and determining the method test result as the test result.
Optionally, executing the test case to obtain a test result obtained by accessing the test data in the built-in database according to the test logic by the code to be tested, including:
Obtaining an access result, wherein the access result is data returned by the built-in database for responding to the code to be tested and accessing the test data in the built-in database according to the test logic;
and generating a test result indicating that the test passes when the access result is consistent with the test data in the built-in database.
Optionally, obtaining a test case corresponding to the code to be tested includes:
Acquiring a hierarchy of the code to be tested, wherein the hierarchy comprises at least one hierarchy;
For any one of the levels, acquiring a unit test case corresponding to the level, wherein the unit test case is used for testing codes under the level;
and determining the unit test case as the test case.
Optionally, obtaining the unit test case corresponding to the hierarchy includes:
acquiring a method identifier of each data method in the hierarchy;
Acquiring method test cases corresponding to the data methods by utilizing the method identifiers;
And determining the method test case as the unit test case.
A second aspect provides a data testing apparatus comprising:
the system comprises an acquisition module, a test module and a test module, wherein the acquisition module is used for acquiring a test case corresponding to a code to be tested, and the test case is used for describing test logic for testing the code to be tested;
The writing module is used for acquiring the test data in the test case and writing the test data into the built-in database by utilizing a database script; the writing the test data into the built-in database by using the database script comprises the following steps: acquiring a database execution script in the database script and a database mode script matched with the database execution script; the database mode script comprises a data structure corresponding to newly added data or modified data in a software project to which a code to be tested belongs, and the data structure is used for identifying the attribute of test data; acquiring a data structure corresponding to the test data from the database mode script; executing a script by using the database, and writing the test data into the built-in database according to the data structure;
And the test module is used for executing the test case and obtaining a test result obtained by accessing the test data in the built-in database according to the test logic by the code to be tested.
In a third aspect, there is provided an electronic device comprising: the device comprises a processor, a memory and a communication bus, wherein the processor and the memory are communicated with each other through the communication bus;
the memory is used for storing a computer program;
the processor is configured to execute the program stored in the memory, and implement the data testing method according to the first aspect.
In a fourth aspect, a computer readable storage medium is provided, storing a computer program, which when executed by a processor implements the data testing method according to the first aspect.
Compared with the prior art, the technical scheme provided by the embodiment of the application has the following advantages: according to the method provided by the embodiment of the application, the test cases corresponding to the codes to be tested and the test data in the test cases are obtained, the test data are written into the built-in database by utilizing the database script, the test cases are executed, and the test results obtained by accessing the test data in the built-in database according to the test logic of the codes to be tested are obtained. Since the test database is a built-in database in the electronic device, it can be ensured that the environment in the electronic device where the test is performed can access the built-in database.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and together with the description, serve to explain the principles of the invention.
In order to more clearly illustrate the embodiments of the invention or the technical solutions of the prior art, the drawings which are used in the description of the embodiments or the prior art will be briefly described, and it will be obvious to a person skilled in the art that other drawings can be obtained from these drawings without inventive effort.
FIG. 1 is a flow chart of a data testing method according to an embodiment of the application;
FIG. 2 is a flow chart of another data testing method according to an embodiment of the application;
FIG. 3 is a flow chart of another data testing method according to an embodiment of the application;
FIG. 4 is a flowchart of another data testing method according to an embodiment of the present application;
FIG. 5 is a flowchart of another data testing method according to an embodiment of the present application;
FIG. 6 is a flowchart of another data testing method according to an embodiment of the present application;
FIG. 7 is a schematic diagram of a data testing device according to an embodiment of the present application;
fig. 8 is a schematic structural diagram of an electronic device according to an embodiment of the application.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the technical solutions of the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application, and it is apparent that the described embodiments are some embodiments of the present application, but not all embodiments of the present application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
It should be noted that the terms "first," "second," and the like in the description and the claims of the present application and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the application described herein may be implemented in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
The embodiment of the application provides a data testing method, which can be applied to any electronic device, wherein the electronic device can comprise a smart Phone (such as an Android Mobile Phone, an iOS Mobile Phone, a Windows Phone Mobile Phone and the like), a tablet personal computer, a palm computer, a notebook computer, a video matrix, a monitoring platform, a Mobile internet device (MID, mobile INTERNET DEVICES) or a wearable device and the like, and the method is merely illustrative, but not exhaustive, and comprises but is not limited to the device;
as shown in fig. 1, the method may include the steps of:
step 101, obtaining a test case corresponding to the code to be tested.
The test case is used for describing test logic for testing the code to be tested. The test case at least comprises a test code.
Alternatively, the test code corresponding to the code to be tested may be written in advance according to the hierarchical architecture of the code to be tested, and the test case corresponding to the code to be tested may be obtained.
Taking the code to be tested as the Service logic code as an example, the hierarchy of the Service logic code may include three levels of a Controller layer, a Service layer and a Dao layer.
The Controller layer belongs to the control layer and is used for receiving the request and returning a calling result; the Service layer belongs to a Service logic layer and is used for storing most of Service logic; the Dao layer serves as a data access layer for querying data from the database and encapsulating the data as objects.
For example, when the Controller layer implements the above functions, the data methods in the Controller layer may be getBtId methods and create methods, where the getBtId methods are used to query data according to a unique id, and the create methods are used to receive json data transferred by a page, create an id object corresponding to the json data, and store the id object in a database.
Illustratively, the Service layer is used for calling the data method of the Dao layer to complete the persistence of the data.
Illustratively, the Dao layer, when implementing the above functions, can integrate Mybatis, provide ORM (object relational mapping ) functions, directly access the database, and provide database access support for upper layers.
MyBatis is a persistent layer framework that supports common SQL queries, stored procedures, and high-level mappings.
The ORM is used for realizing conversion between data of different types of systems in an object-oriented programming language.
The three levels of the Controller layer, the Service layer and the Dao layer have a dependency relationship, specifically, the Controller layer depends on the Service layer and the Service layer depends on the Dao layer.
Alternatively, according to the dependency relationship between the levels, the unit test cases corresponding to the levels can be written.
For example, taking the code to be tested as the service logic code still as an example, the process of writing the unit test cases corresponding to each level may be:
first, test code of the Controller layer is written:
In setUp, the mock object is initialized, the mockMvc object is created here, and since the object tested at this time is the Controller layer, the Service object is in a separate test class, so that the actual Service code of the Service layer is shielded, and a virtual Service object (i.e. the mock object) is created and injected, focusing on testing the Controller layer.
Wherein, the mock object is an object in a mock test; mock testing refers to a testing method in which a virtual object is used to create objects that are not easily constructed or easily obtained for testing during testing.
Optionally, the code to be tested of the Controller layer includes, but is not limited to, codes corresponding to getById methods and create methods, so that the test code of the Controller layer written based on the above methods includes, but is not limited to, method test codes corresponding to getById methods and create methods.
Second, test code for Service layer:
Similar to the Controller level test, the Service level test also needs to remain independent, where the test is performed using virtual dao objects, and initialization of the test class is completed at setUp.
Optionally, the code to be tested of the Service layer includes, but is not limited to, codes corresponding to getById methods and create methods, so that the test code of the Service layer written based on the above methods includes, but is not limited to, method test codes corresponding to getById methods and create methods.
Finally, test code for Dao layer:
The Dao layer code does not need mock testing, and because of the need to test the operations to access the database, it is directly injected with Resource resources, and the test class needs to inherit AbstractBaseTest and start the application container.
Wherein Resource resources are non-executable data that is logically deployed with code. The Resource may be displayed in the code as an error message or as part of a user interface. The Resource may contain various forms of data including strings, images, and persistent objects, among others.
Alternatively, the code to be tested of the Dao layer may include, but is not limited to, codes corresponding to getById method and create method, so the test code of the Dao layer written based on the above method includes, but is not limited to, method test code corresponding to getById method and create method.
It should be noted that, although the Controller layer, the Service layer, and the Dao layer may each include getById methods and create methods, in different levels, method identifiers corresponding to method test cases written for the same method are different.
For example, at different levels, the method identifier corresponding to getById methods may be Run 'getById ()', run 'getById ()' with Coverage, or Run 'getById ()' with 'Java Flight Recorder', or the like.
Alternatively, the present embodiment may perform the test with each level as the smallest testable unit in the code to be tested. Specifically, when the unit test cases of each level are written, the dependency relationship between the levels is removed, so that any one of the unit test cases corresponding to each level can be used as the test case corresponding to the code to be tested.
In the case of taking a unit test case as a test case corresponding to a code to be tested, referring specifically to fig. 2, step 101 may include the following steps:
step 201, obtaining a hierarchy of codes to be tested, wherein the hierarchy comprises at least one hierarchy;
Step 202, for any one hierarchy, obtaining a unit test case corresponding to the hierarchy, where the unit test case is used to test codes under the hierarchy;
step 203, determining the unit test case as a test case.
Optionally, the test code in the unit test cases corresponding to the hierarchy may be a method test code for testing a data method, so that the unit test cases corresponding to the hierarchy may be obtained according to the data method included in the code under the hierarchy.
Optionally, since the method identifiers corresponding to the method test cases of the same data method in different levels are different, the unit test cases corresponding to the levels can be obtained according to the method identifiers of the data methods in the levels.
Specifically, as shown in fig. 3, step 202 may include the steps of:
Step 301, obtaining a method identifier of each data method in the hierarchy;
step 302, acquiring a method test case corresponding to each data method by utilizing a method identifier;
step 303, determining the method test case as a unit test case.
Step 102, obtaining test data in the test cases, and writing the test data into the built-in database by utilizing the database script.
In this embodiment, the built-in database and the test case are provided in the same electronic device.
The built-in database may be an in-memory database in the electronic device, for example.
The test data is basic data for testing the code to be tested.
Taking the code to be tested as the code for realizing the query function as an example, when verifying whether the code to be tested is correct, the test data can be the preset data to be queried of the code to be tested.
For example, the test data may be the ID of the user and an identification card number, and the code to be tested is used to query the built-in database for the identification card number corresponding to the ID of the user.
In this embodiment, a database script is preset, and writing test data into the built-in database is implemented by loading the database script.
Alternatively, the database scripts may include database execution scripts and database schema scripts.
Illustratively, the database execution script may be in the form of a data.sql file and the database schema script may be in the form of a schema.sql file.
When new data are added or data are modified in the iteration of the software project to which the code to be tested belongs, the DDL statement is added to the tail end of the file, and the original DDL statement cannot be modified; the data.sql file is composed of DML statements that are appended to the end of the file when there is a new row record or a modified row record in an iteration of the software project.
Wherein, the database mode script comprises a data structure; the database execution script is used for writing test data into the built-in database according to the data structure, the test data is maintained in the data.sql file, the whole software project engineering period can be penetrated, the exposure of the test data can be avoided, the modification of other people can be avoided, and meanwhile, when the test is executed at any time, the data is ready to be obtained for the test case to process and judge, so that the test can be ensured to be executed at any time.
Wherein the data structure is used to identify attributes of the test data.
For example, the attribute of the test data may be a user name, an identification number, a weight, or the like. When the test data is Zhang Sanzhu, zhang Sanzhu can be stored in the built-in database with the user name.
Optionally, in order to timely sense the change of the underlying data structure, in this embodiment, the database execution script and the database mode script are set to have a matching relationship, so that after the data structure in the database mode script changes, the developer is prompted to timely check through the failure of writing test data into the built-in database.
Specifically, referring to fig. 4, fig. 4 is a schematic diagram showing an implementation manner of writing test data into a built-in database by using a database script according to the present embodiment, including the following steps:
step 401, acquiring a database execution script in a database script and a database mode script matched with the database execution script;
step 402, obtaining a data structure corresponding to test data from a database mode script;
and 403, executing the script by using the database, and writing test data into the built-in database according to the data structure.
Optionally, in this embodiment, a matching relationship between the database mode script and the database execution script may be pre-established through a script identifier of the database mode script, and when the database execution script and the database mode script need to be loaded, the database mode script corresponding to the database execution script is obtained through the script identifier matched with the database execution script.
Wherein the script identification of the database schema script is related to a data structure in the database schema script. Thus, when a change occurs in the data structure in the database schema script, the script identification of the database schema script changes accordingly.
For example, the script identification of the database schema script when the data structure is "user name" is different from the script identification of the database schema script when the data structure is "name".
And 103, executing the test case to obtain a test result obtained by accessing test data in the built-in database according to the test logic by the code to be tested.
In this embodiment, the test cases may include a plurality of individual test cases, and each individual test case may correspond to one method test case.
Optionally, the embodiment can test the code to be tested through the data in the single test case and the built-in database, and can test the code to be tested through the data in the built-in database and the test case consisting of all the single test cases.
When the code to be tested is tested by the test cases consisting of all the single test cases and the data in the built-in database, as shown in fig. 5, the following steps may be included:
Step 501, obtaining an access result;
The access result is data returned by the built-in database for responding to the code to be tested and accessing the test data in the built-in database according to the test logic.
Step 502, when the access result is consistent with the test data, generating a test result indicating that the test is passed.
Because the data in the built-in database may include non-test data not related to the test data in addition to the test data, when the access result is consistent with the test data, a test result indicating that the test passed may be generated; when the access result is inconsistent with the test data, a test result may be generated indicating that the test failed.
Taking a code to be tested as an example of a code for realizing the query function, and generating a test result indicating that the test passes when data obtained by query from the built-in database belongs to test data; and when the data obtained by inquiring from the database does not belong to the data test data or is not obtained by inquiring, generating a test result indicating that the test fails.
For example, the test data includes an identification card number B of a user with ID a, the test case is used to make a code for implementing the query function query the identification card number B from the built-in database according to a, when the data obtained by the query from the built-in database is C, since the data C is inconsistent with the identification card number B in the test data, it can be determined that the access result (i.e., the data C) is inconsistent with the test data, and when the data obtained by the query from the built-in database is B, since the data B is identical with the identification card number B in the test data, it can be determined that the access result (i.e., the data B) is consistent with the test data.
Optionally, in the process of obtaining the test result, the number of test cases of the execution method, the number of failed test cases of the method, the number of error reporting of test cases of the method and the like can also be recorded.
Optionally, after the test result is obtained, a test report may also be generated based on the test result.
Optionally, when the code to be tested is tested by the test cases formed by all the single test cases and the data in the built-in database, the test report may include, besides the test result, the number of test cases for executing each method, the number of failed test cases for each method, the number of error reporting cases for each method, and the like.
Alternatively, the test cases may be executed by a container environment in the electronic device in this embodiment.
Taking a software code of which the code to be tested is a Java server as an example, a container environment in the electronic equipment can adopt a Spring Boot container with industry facts and standards.
According to the method provided by the embodiment of the application, the test cases corresponding to the codes to be tested and the test data in the test cases are obtained, the test data are written into the built-in database by utilizing the database script, the test cases are executed, and the test results obtained by the codes to be tested according to the test logic and the test data in the built-in database are obtained. Since the test database is a built-in database in the electronic device, it can be ensured that the environment in the electronic device where the test is performed can access the built-in database.
When the external test database is adopted, when the external test database is not available or the electronic equipment currently executing the unit test does not have the access right of the external test database, the electronic equipment cannot be connected to the external test database, and further the unit test cannot be carried out; and when the test data of the unit test is exposed in the external test database, effective maintenance cannot be performed, and any person can operate the test data in the external test database, such as data modification results, data loss caused by insufficient space of the electronic equipment where the external test database is located, database rebuilding caused by cleaning of a disk, and all data in the external database are emptied, and when the unit test needs to be executed again, the unit test cannot be passed, and at the moment, whether the test fails or not is caused by code logic modification cannot be judged, and time and effort are required for a developer to check.
By adopting the technical scheme of the embodiment, the test data is written into the internal database, so that the problem of exposing the data to the outside is avoided, and the problem caused by exposing the data is avoided.
Also, when an external test database is used, since the external database is relied on, operations such as network communication and I/O require a lot of time and take a long time when the external test database is accessed.
By adopting the technical scheme of the embodiment, because the built-in database is adopted, the time consumption of a network is avoided, and the test execution speed is relatively high.
Also, when an external test database is employed, the unit test cannot be regressed in its entirety due to the long time consumption; by adopting the technical scheme of the embodiment of the application, the test can be completely regressed because the test speed is relatively high.
Finally, when the external test database is adopted, as the data in the external test database can be changed, after the data is changed, the test cases cannot be executed, so that the unit test is mostly a one-time test, and the life cycle of the unit test is difficult to effectively manage; by adopting the technical scheme provided by the embodiment of the application, the internal database is written in the test data, so that the external modification can be shielded, the test can be further executed at any time, and the life cycle of the whole software is realized through the test data.
An embodiment of the present application provides a data testing method, as shown in fig. 6, which may include the following steps:
Step 601, starting a Spring Boot container and a built-in database;
Taking a business logic code as a Java server project as an example, the embodiment selects maven as package dependency management, and adopts a Spring Boot container of an industry fact standard as a project basic frame.
Wherein maven is a dependent package management tool in the Java development field.
The embodiment needs to create a maven project in advance, and introduce the dependency jar package needed by the project through the pon file.
The jar packet to be introduced mainly may include:
SpringBoot for providing a project-initiated container environment.
Spring-test to provide the execution environment needed for unit testing.
Spring-boot-starter-test for providing the execution environment needed for unit testing.
The spring-boot-starter-jdbc is used for integrating jdbc for the spring boot and is used for accessing the database.
The MyBatis-spring-boot-starter is used for integrating the ORM framework MyBatis, so that the database query result can be conveniently packaged into a Java object.
H2: the relational database implemented by pure Java supports the sql standard, and the JDBC access interface can be integrated into engineering.
Mysql-connector-java: the MySQL database driver is used for accessing the database.
Junit-vintage-engine: java Unit framework JunitTest compares the new versions.
Step 602, obtaining a test case corresponding to the business logic code and test data in the test case;
Step 603, loading a database execution script and a database mode script to insert test data into the built-in database;
step 604, executing the test case to obtain a test result obtained by accessing test data in the built-in database according to the test logic by the code to be tested;
step 605, generating a unit test report based on the test result.
Based on the same conception, the embodiment of the present application provides a data testing device, and the specific implementation of the device may be referred to the description of the embodiment of the method, and the repetition is omitted, as shown in fig. 7, where the device mainly includes:
The acquiring module 701 is configured to acquire a test case corresponding to a code to be tested, where the test case is used to describe test logic for testing the code to be tested;
The writing module 702 is configured to obtain test data in a test case, and write the test data into a built-in database by using a database script;
The test module 703 is configured to execute a test case, and obtain a test result obtained by accessing test data in the built-in database according to the test logic by the code to be tested.
Optionally, the writing module 702 is specifically configured to:
acquiring a database execution script in a database script and a database mode script matched with the database execution script;
Acquiring a data structure corresponding to the test data from the database mode script;
and executing the script by using the database, and writing test data into the built-in database according to the data structure.
Optionally, the writing module 702 is specifically configured to:
Acquiring script identification of a database mode script, wherein the script identification is related to a data structure;
When the script corresponding to the script identification exists in the database script, determining the script corresponding to the script identification as the database mode script.
Optionally, the test module 703 is specifically configured to:
Obtaining a method test case corresponding to a preset data method from the test cases, wherein the preset data method is any data method in the code to be tested, and the method test case is used for describing method test logic of the preset data method;
And obtaining a method test result obtained by the preset data method according to the method test logic and the test data in the built-in database, and determining the method test result as the test result.
Optionally, the test module 703 is specifically configured to:
Obtaining an access result, wherein the access result is data returned by the built-in database for responding to the code to be tested and accessing test data in the built-in database according to test logic;
And generating a test result indicating that the test passes when the access result is consistent with the test data in the built-in data.
Optionally, the acquiring module 701 is specifically configured to:
acquiring a hierarchy of codes to be tested, wherein the hierarchy comprises at least one hierarchy;
for any one hierarchy, acquiring a unit test case corresponding to the hierarchy, wherein the unit test case is used for testing codes under the hierarchy;
and determining the unit test cases as test cases.
Optionally, the acquiring module 701 is specifically configured to:
Acquiring a method identifier of each data method in the hierarchy;
Obtaining method test cases corresponding to the data methods by utilizing the method identifiers;
And determining the method test case as a unit test case.
Based on the same concept, the embodiment of the application also provides an electronic device, as shown in fig. 8, where the electronic device mainly includes: a processor 801, a memory 802, and a communication bus 803, wherein the processor 801 and the memory 802 complete communication with each other through the communication bus 803. The memory 802 stores a program executable by the processor 801, and the processor 801 executes the program stored in the memory 802 to implement the following steps:
Acquiring a test case corresponding to a code to be tested, wherein the test case is used for describing test logic of the code to be tested; acquiring test data in the test case, and writing the test data into a built-in database by utilizing a database script; executing the test case to obtain a test result obtained by accessing the to-be-tested data in the built-in database according to the test logic.
Optionally, writing test data to the built-in database using the database script includes:
acquiring a database execution script in a database script and a database mode script matched with the database execution script;
Acquiring a data structure corresponding to the test data from the database mode script;
and executing the script by using the database, and writing test data into the built-in database according to the data structure.
Optionally, obtaining a database schema script that matches the database execution script includes:
Acquiring script identification of a database mode script, wherein the script identification is related to a data structure;
When the script corresponding to the script identification exists in the database script, determining the script corresponding to the script identification as the database mode script.
Optionally, executing the test case to obtain a test result obtained by accessing to-be-tested data in the built-in database according to the test logic by the code to be tested, including:
Obtaining a method test case corresponding to a preset data method from the test cases, wherein the preset data method is any data method in the code to be tested, and the method test case is used for describing method test logic of the preset data method;
And obtaining a method test result obtained by the preset data method according to the method test logic and the test data in the built-in database, and determining the method test result as the test result.
Optionally, executing the test case to obtain a test result obtained by accessing to-be-tested data in the built-in database according to the test logic by the code to be tested, including:
Obtaining an access result, wherein the access result is data returned by the built-in database for responding to the code to be tested and accessing test data in the built-in database according to test logic;
And generating a test result indicating that the test passes when the access result is consistent with the test data in the built-in data.
Optionally, obtaining a test case corresponding to the code to be tested includes:
acquiring a hierarchy of codes to be tested, wherein the hierarchy comprises at least one hierarchy;
for any one hierarchy, acquiring a unit test case corresponding to the hierarchy, wherein the unit test case is used for testing codes under the hierarchy;
and determining the unit test cases as test cases.
Optionally, obtaining the unit test case corresponding to the hierarchy includes:
Acquiring a method identifier of each data method in the hierarchy;
Obtaining method test cases corresponding to the data methods by utilizing the method identifiers;
And determining the method test case as a unit test case.
The communication bus 803 mentioned in the above-mentioned electronic device may be a peripheral component interconnect standard (PERIPHERAL COMPONENT INTERCONNECT, abbreviated to PCI) bus or an extended industry standard architecture (Extended Industry Standard Architecture, abbreviated to EISA) bus, or the like. The communication bus 803 may be divided into an address bus, a data bus, a control bus, and the like. For ease of illustration, only one thick line is shown in fig. 8, but not only one bus or one type of bus.
The memory 802 may include random access memory (Random Access Memory, RAM) or may include non-volatile memory (non-volatile memory), such as at least one disk memory. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor 801.
The processor 801 may be a general-purpose processor, including a central Processing unit (Central Processing Unit, CPU), a network processor (Network Processor, NP), a digital signal processor (DIGITAL SIGNAL Processing, DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable gate array (FPGA) or other Programmable logic device, discrete gate or transistor logic device, or discrete hardware components.
In yet another embodiment of the present application, there is also provided a computer-readable storage medium having stored therein a computer program which, when run on a computer, causes the computer to perform the data testing method described in the above embodiment.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, the processes or logic described in accordance with embodiments of the present application are produced in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, by a wired (e.g., coaxial cable, optical fiber, digital Subscriber Line (DSL)), or wireless (e.g., infrared, microwave, etc.) means from one website, computer, server, or data center to another. The computer readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains an integration of one or more available media. The usable medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape, etc.), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk), etc.
It should be noted that in this document, relational terms such as "first" and "second" and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The foregoing is only a specific embodiment of the invention to enable those skilled in the art to understand or practice the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (9)

1. A method of testing data, comprising:
acquiring a test case corresponding to a code to be tested, wherein the test case is used for describing test logic for testing the code to be tested;
acquiring test data in the test case, and writing the test data into a built-in database by utilizing a database script;
Executing the test case to obtain a test result obtained by accessing the test data in the built-in database according to the test logic by the code to be tested;
The writing the test data into the built-in database by using the database script comprises the following steps:
Acquiring a database execution script in the database script and a database mode script matched with the database execution script; the database mode script comprises a data structure corresponding to newly added data or modified data in a software project to which a code to be tested belongs, and the data structure is used for identifying the attribute of test data;
acquiring a data structure corresponding to the test data from the database mode script;
And executing a script by using the database, and writing the test data into the built-in database according to the data structure.
2. The method of claim 1, wherein obtaining a database schema script that matches the database execution script comprises:
acquiring a script identification of the database mode script, wherein the script identification is related to the data structure;
And when the script corresponding to the script identification exists in the database script, determining the script corresponding to the script identification as the database mode script.
3. The method of claim 1, wherein executing the test case to obtain test results for the code under test according to the test logic accessing the test data in the built-in database comprises:
Acquiring a method test case corresponding to a preset data method from the test cases, wherein the preset data method is any data method in the code to be tested, and the method test case is used for describing method test logic of the preset data method;
And obtaining the preset data method, testing logic according to the method, accessing the method test result obtained by the test data in the built-in database, and determining the method test result as the test result.
4. The method of claim 1, wherein executing the test case to obtain test results for the code under test according to the test logic accessing the test data in the built-in database comprises:
Obtaining an access result, wherein the access result is data returned by the built-in database for responding to the code to be tested and accessing the test data in the built-in database according to the test logic;
and generating a test result indicating that the test passes when the access result is consistent with the test data in the built-in database.
5. The method of claim 1, wherein obtaining a test case corresponding to a code to be tested comprises:
Acquiring a hierarchy of the code to be tested, wherein the hierarchy comprises at least one hierarchy;
For any one of the levels, acquiring a unit test case corresponding to the level, wherein the unit test case is used for testing codes under the level;
and determining the unit test case as the test case.
6. The method of claim 5, wherein obtaining unit test cases corresponding to the hierarchy comprises:
acquiring a method identifier of each data method in the hierarchy;
Acquiring method test cases corresponding to the data methods by utilizing the method identifiers;
And determining the method test case as the unit test case.
7.A data testing apparatus, comprising:
the system comprises an acquisition module, a test module and a test module, wherein the acquisition module is used for acquiring a test case corresponding to a code to be tested, and the test case is used for describing test logic for testing the code to be tested;
The writing module is used for acquiring the test data in the test case and writing the test data into the built-in database by utilizing a database script; the writing the test data into the built-in database by using the database script comprises the following steps: acquiring a database execution script in the database script and a database mode script matched with the database execution script; the database mode script comprises a data structure corresponding to newly added data or modified data in a software project to which a code to be tested belongs, and the data structure is used for identifying the attribute of test data; acquiring a data structure corresponding to the test data from the database mode script; executing a script by using the database, and writing the test data into the built-in database according to the data structure;
And the test module is used for executing the test case and obtaining a test result obtained by accessing the test data in the built-in database according to the test logic by the code to be tested.
8. An electronic device, comprising: the device comprises a processor, a memory and a communication bus, wherein the processor and the memory are communicated with each other through the communication bus;
the memory is used for storing a computer program;
the processor is configured to execute a program stored in the memory, and implement the data testing method of any one of claims 1 to 6.
9. A computer readable storage medium storing a computer program, wherein the computer program when executed by a processor implements the data testing method of any of claims 1-6.
CN202110266657.2A 2021-03-11 2021-03-11 Data testing method, device, equipment and storage medium Active CN112965905B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110266657.2A CN112965905B (en) 2021-03-11 2021-03-11 Data testing method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110266657.2A CN112965905B (en) 2021-03-11 2021-03-11 Data testing method, device, equipment and storage medium

Publications (2)

Publication Number Publication Date
CN112965905A CN112965905A (en) 2021-06-15
CN112965905B true CN112965905B (en) 2024-06-18

Family

ID=76277326

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110266657.2A Active CN112965905B (en) 2021-03-11 2021-03-11 Data testing method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112965905B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113835751B (en) * 2021-09-30 2024-01-09 北京达佳互联信息技术有限公司 Code testing method, device, electronic equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108228965A (en) * 2017-12-06 2018-06-29 北京物芯科技有限责任公司 A kind of emulation verification method of storage unit, device and equipment
CN110750457A (en) * 2019-10-21 2020-02-04 中国民航信息网络股份有限公司 Automatic unit testing method and device based on memory database
CN112286779A (en) * 2019-07-23 2021-01-29 腾讯科技(深圳)有限公司 Test task processing method and device, storage medium and computer equipment

Family Cites Families (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7406679B2 (en) * 2002-05-10 2008-07-29 International Business Machines Corporation Testing environment for database server side logic
JP2010198479A (en) * 2009-02-26 2010-09-09 Hitachi Software Eng Co Ltd System for automatically executing application test
US9274936B2 (en) * 2013-05-29 2016-03-01 Sap Portals Israel Ltd Database code testing framework
CN107688531B (en) * 2017-06-20 2019-02-22 平安科技(深圳)有限公司 Geo-database integration test method, device, computer equipment and storage medium
CN107832217A (en) * 2017-11-09 2018-03-23 政采云有限公司 A kind of automated testing method and device
US10621077B2 (en) * 2018-05-16 2020-04-14 Servicenow, Inc. Dependency mapping between program code and tests to rapidly identify error sources
WO2020039444A1 (en) * 2018-08-24 2020-02-27 Satixfy Israel Ltd. Translation of embedded software api's for carrying out software testing
CN110347545A (en) * 2019-05-21 2019-10-18 深圳壹账通智能科技有限公司 A kind of test method and device of business platform cache policy
CN111625445B (en) * 2020-04-23 2024-07-05 平安国际智慧城市科技股份有限公司 Java-based test framework construction method, java-based test framework construction device and storage medium
CN112148270B (en) * 2020-08-12 2024-05-14 珠海伟诚科技股份有限公司 Real-time computing and data interaction method, system and medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108228965A (en) * 2017-12-06 2018-06-29 北京物芯科技有限责任公司 A kind of emulation verification method of storage unit, device and equipment
CN112286779A (en) * 2019-07-23 2021-01-29 腾讯科技(深圳)有限公司 Test task processing method and device, storage medium and computer equipment
CN110750457A (en) * 2019-10-21 2020-02-04 中国民航信息网络股份有限公司 Automatic unit testing method and device based on memory database

Also Published As

Publication number Publication date
CN112965905A (en) 2021-06-15

Similar Documents

Publication Publication Date Title
WO2020000706A1 (en) Database comparison-based interface testing method and system, device and storage medium
US8832658B2 (en) Verification framework for business objects
CN105760292B (en) A kind of assertion verification method and apparatus for unit testing
CN109302522A (en) Test method, device and computer system and medium
CN111897724B (en) Automatic testing method and device suitable for cloud platform
WO2019178967A1 (en) Jmeter-based stress testing method and apparatus, and device and storage medium
US20160259636A1 (en) Software patch evaluator
CN112199300B (en) Interface testing method and device, electronic equipment and storage medium
CN112256321A (en) Static library packaging method and device, computer equipment and storage medium
CN104679500B (en) Method and device for realizing automatic generation of entity class
CN112685020B (en) Method and device for dynamically creating service interface, electronic equipment and storage medium
US11379198B1 (en) Call graph enhancement using stitching algorithm
US20210157924A1 (en) Coverage of web appliction analysis
CN112965905B (en) Data testing method, device, equipment and storage medium
CN107450909A (en) The treating method and apparatus of validity check is integrated for SDK
CN114238085A (en) Interface testing method and device, computer equipment and storage medium
CN113806209A (en) Interface testing method, frame, computer device and storage medium
US8949421B2 (en) Techniques for discovering database connectivity leaks
CN112433933A (en) Method and equipment for automatically testing interface
CN114443337B (en) JS-based log analysis method and device, electronic equipment and medium
CN116048991A (en) Construction method and device of multi-source data service REST API interface
CN103677846A (en) SQLite database development kit and development method thereof
CN114528214A (en) Unit testing method and device
CN110442370B (en) Test case query method and device
US11100131B2 (en) Simulation of a synchronization of records

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
CB02 Change of applicant information
CB02 Change of applicant information

Address after: 601, 6 / F, building 2, No. 18, Kechuang 11th Street, Daxing District, Beijing, 100176

Applicant after: Jingdong Technology Information Technology Co.,Ltd.

Address before: 601, 6 / F, building 2, No. 18, Kechuang 11th Street, Daxing District, Beijing, 100176

Applicant before: Jingdong Shuke Haiyi Information Technology Co.,Ltd.

GR01 Patent grant
GR01 Patent grant