Unit testing method and related equipment

Through an automated unit testing method, the unit to be tested is automatically called using the test entrance and data in the test file, solving the problem of inefficient unit testing in the existing technology and achieving efficient automated testing.

CN119938527APending Publication Date: 2025-05-06APPEON TECH SZ LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411993186.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-30
Publication Date
2025-05-06

AI Technical Summary

Technical Problem

Existing unit testing methods rely on testers to manually write test code, resulting in high labor costs and inefficient testing.

Method used

By obtaining the test files of the unit to be tested, including the test entrance and test data, automatically call the unit to be tested, and determining the test results based on the actual output and expected results, reducing or even eliminating the need to write unit test code.

Benefits of technology

It greatly improves unit testing efficiency, reduces the workload of developers to manually write test cases, and realizes automated unit testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119938527A_ABST
    Figure CN119938527A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a unit testing method and related equipment, which are used for improving the unit testing efficiency. The method comprises the steps that a test file of a to-be-tested unit is obtained, the test file comprises a test entry and test data, and the test data comprises test parameters and expected results corresponding to the test parameters; calling the to-be-tested unit based on the test parameters and the test entry to obtain actual output corresponding to the test parameters; and determining a test result of the to-be-tested unit based on the actual output corresponding to the test parameter and an expected result corresponding to the test parameter.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of software testing, and in particular to unit testing methods and related equipment. Background Art

[0002] Unit testing refers to the inspection and verification of the smallest testable unit in the software.

[0003] The existing implementation of unit testing mainly relies on the test code written by the tester. By running the test code, the functions of the unit under test can be quickly verified. However, since the test code is written by the tester based on the functions that the unit under test needs to implement and the possible errors, it takes a lot of manpower, which leads to the overall low efficiency of unit testing. Summary of the invention

[0004] The embodiments of the present application provide a unit testing method and related equipment for improving the efficiency of unit testing.

[0005] A first aspect of an embodiment of the present application provides a unit testing method, comprising:

[0006] Obtain a test file of the unit to be tested, wherein the test file includes a test entry and test data, wherein the test data includes test parameters and expected results corresponding to the test parameters;

[0007] Calling the unit under test based on the test parameters and the test entry to obtain actual output corresponding to the test parameters;

[0008] The test result of the unit under test is determined based on the actual output corresponding to the test parameter and the expected result corresponding to the test parameter.

[0009] In a specific implementation, determining the test result of the unit under test based on the actual output corresponding to the test parameter and the expected result corresponding to the test parameter includes:

[0010] Determining a target determination strategy corresponding to the unit under test;

[0011] The test result of the unit under test is determined based on the target determination strategy, the actual output corresponding to the test parameter, and the expected result corresponding to the test parameter.

[0012] In a specific implementation, the result determination strategy is divided into a normal determination strategy and an abnormal determination strategy, and the target determination strategy corresponding to the unit under test is determined, including:

[0013] If the actual output corresponding to the test parameter belongs to the normal return of the unit under test, determining the target determination strategy corresponding to the unit under test from the normal determination strategy;

[0014] If the actual output corresponding to the test parameter belongs to a thrown error of the unit under test, a target determination strategy corresponding to the unit under test is determined from the exception determination strategy.

[0015] In a specific implementation, the determining the target determination strategy corresponding to the unit under test includes:

[0016] If the unit under test does not have a corresponding preset determination strategy, the preset determination strategy corresponding to the test entry is used as the target determination strategy corresponding to the unit under test;

[0017] If the unit under test has a corresponding preset determination strategy, the preset determination strategy corresponding to the unit under test is used as the target determination strategy corresponding to the unit under test.

[0018] In a specific implementation, if the target determination strategy corresponding to the unit under test is a summary comparison strategy, determining the test result of the unit under test based on the target determination strategy, the actual output corresponding to the test parameter, and the expected result corresponding to the test parameter includes:

[0019] Obtaining an actual summary value of the actual output and an expected summary value of the expected result;

[0020] A test result of the unit under test is determined based on whether the actual digest value is consistent with the expected digest value.

[0021] In a specific implementation, before the unit under test is called based on the test parameters and the test entry to obtain the actual output corresponding to the test parameters, the test file also includes an initialization unit and initialization parameters corresponding to the initialization unit, and the unit testing method also includes:

[0022] calling the initialization unit based on the initialization parameters corresponding to the initialization unit;

[0023] If the initialization unit is called based on the initialization parameter, the step of calling the unit under test based on the test parameter and the test entry is performed.

[0024] A second aspect of an embodiment of the present application provides a unit testing device, including:

[0025] An acquisition unit, used for acquiring a test file of the unit to be tested, wherein the test file includes a test entry and test data, wherein the test data includes test parameters and expected results corresponding to the test parameters;

[0026] A test unit, used to call the unit under test based on the test parameters and the test entry to obtain an actual output corresponding to the test parameters;

[0027] A determination unit is used to determine the test result of the unit under test based on the actual output corresponding to the test parameter and the expected result corresponding to the test parameter.

[0028] In a specific implementation, the determination unit is specifically used to determine a target determination strategy corresponding to the unit under test; and determine the test result of the unit under test based on the target determination strategy, the actual output corresponding to the test parameters, and the expected result corresponding to the test parameters.

[0029] In a specific implementation, the result judgment strategy is divided into a normal judgment strategy and an abnormal judgment strategy. The determination unit is specifically used to determine the target judgment strategy corresponding to the unit under test from the normal judgment strategy if the actual output corresponding to the test parameter belongs to the normal return of the unit under test; if the actual output corresponding to the test parameter belongs to the thrown error of the unit under test, determine the target judgment strategy corresponding to the unit under test from the abnormal judgment strategy.

[0030] In a specific implementation, the determination unit is specifically used to use the preset judgment strategy corresponding to the test entry as the target judgment strategy corresponding to the unit under test if there is no corresponding preset judgment strategy for the unit under test; if there is a corresponding preset judgment strategy for the unit under test, then the preset judgment strategy corresponding to the unit under test is used as the target judgment strategy corresponding to the unit under test.

[0031] In a specific implementation, if the target determination strategy corresponding to the unit to be tested is a summary comparison strategy, the determination unit is specifically used to obtain the actual summary value of the actual output and the expected summary value of the expected result; based on whether the actual summary value and the expected summary value are consistent, determine the test result of the unit to be tested.

[0032] In a specific implementation, before calling the unit under test based on the test parameters and the test entry to obtain the actual output corresponding to the test parameters, the test file also includes an initialization unit and initialization parameters corresponding to the initialization unit, and the test unit is also used to call the initialization unit based on the initialization parameters corresponding to the initialization unit; if the initialization unit is called based on the initialization parameters, the step of calling the unit under test based on the test parameters and the test entry is executed.

[0033] A third aspect of an embodiment of the present application provides a unit testing device, including:

[0034] CPU, memory and input / output interface;

[0035] The memory is a short-term storage memory or a persistent storage memory;

[0036] The central processing unit is configured to communicate with the memory and execute instructions in the memory to perform the method described in the first aspect.

[0037] A fourth aspect of the embodiments of the present application provides a computer program product comprising instructions, and when the computer program product is run on a computer, the computer is caused to execute the method described in the first aspect.

[0038] A fifth aspect of an embodiment of the present application provides a computer storage medium, wherein the computer storage medium stores instructions, and when the instructions are executed on a computer, the computer executes the method described in the first aspect.

[0039] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages: a unit test method and a unit test device driven by test data are provided, thereby greatly reducing or even eliminating the need to write unit test code. The embodiment of the present application is feasible because the test entry of the unit to be tested is determined prior to the implementation of the unit to be tested, that is, the test entry is generally basically determined before the coding of the unit to be tested begins, so the test data can be prepared after the test entry is determined. On this basis, developers only need to configure corresponding test files for different units to be tested, and the unit test for the unit to be tested can be uniformly and automatically executed through the unit test method of the embodiment of the present application, and the corresponding test results can be obtained, without the need for developers to manually write test cases separately for whether the behavior to be tested under different specific conditions meets expectations, thereby improving the overall test efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 A system architecture diagram of the unit testing method disclosed in the embodiment of the present application;

[0041] Figure 2 A schematic diagram of a flow chart of a unit testing method disclosed in an embodiment of the present application;

[0042] Figure 3 A schematic diagram of the structure of the unit test device disclosed in the embodiment of the present application;

[0043] Figure 4 Another structural schematic diagram of the unit testing device disclosed in an embodiment of the present application. DETAILED DESCRIPTION

[0044] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0045] The functions / behaviors of the units developed during the development process are unstable, because program development is a complex task and it is difficult to achieve it overnight. Therefore, unit testing is usually implemented by writing unit test code / cases, and unit test code is generally written based on a certain unit test framework. The reason why unit test code / cases need to be written is related to the characteristics of the software itself. Software units and modules or components can reference each other, and modifications to a unit may affect other units that reference the unit; in addition, the functions of the software are gradually improved, so later maintenance and modifications are very frequent. With unit test cases, all unit test cases can be replayed after the software is modified, that is, automatically verifying whether the functions of all units meet expectations.

[0046] Generally, unit testing is used to determine whether the behavior of a function or method under certain conditions is as expected. A unit often has multiple specific behaviors depending on the input parameters. This requires writing unit test code for each specific behavior, including basic verifications such as parameter boundary values, out-of-bounds values, and normal values.

[0047] Therefore, the embodiments of the present application provide a unit testing method and related equipment to improve the efficiency of unit testing.

[0048] In order to better implement the unit testing method of the embodiment of the present application, the embodiment of the present application provides a Figure 1 The unit test framework shown, the unit test framework of the embodiment of the present application can be deployed in any unit test device. Under the test framework of the embodiment of the present application, the tester only needs to provide a test file containing at least one group of test data and a test entry, wherein each group of test data contains test parameters and expected results, and the test entry is the call or access method of the corresponding unit under test. The unit test device of the embodiment of the present application can automatically parse the test data and the test entry in the test file, and call the unit under test based on the test parameters in each test data in turn. And, determine whether the test data meets the abnormal condition according to the expected results in the corresponding test data, the actual output of the unit under test, and the corresponding result judgment strategy.

[0049] In actual applications, the unit test device also provides the collection and storage of test data, which includes test parameters and expected results. The actual output of the machine corresponding to the test parameters input by programmers during the development process is generally thrown away after use, and there is no systematic management. The unit test device of this application also provides the following functions:

[0050] 1) Provide a data entry interface for developers to input test entry and test data and other contents required to be recorded in the test file.

[0051] 2) According to the test file constructed by inputting in step 1), the unit test of the corresponding unit under test is executed, and the corresponding actual output is obtained.

[0052] 3) Combined process Figure 1 The information storage of relevant test results is shown.

[0053] 4) Organize the data obtained in step 1) and step 3) into JSON format and store it in the test result file.

[0054] The embodiment of the present application only needs to prepare the test file, and the unit testing device provided by the embodiment of the present application can automatically perform unit testing using the prepared test file without the developer having to write unit test code. In addition, the embodiment of the present application provides a data entry interface for the test file to further improve the efficiency of unit testing.

[0055] See also Figure 2 Based on the above-mentioned unit testing framework, the embodiment of the present application provides a unit testing method, which is applied to a unit testing device, and includes the following steps:

[0056] 201. Obtain a test file of the unit to be tested, where the test file includes a test entry and test data, and the test data includes test parameters and expected results corresponding to the test parameters.

[0057] Unit testing refers to checking and verifying the functions of the smallest testable unit in the software. There is no clear standard for the size or scope of the "unit". The unit to be tested in the embodiment of the present application can be a function, method, type, functional module, subsystem or interface, etc. At the same time, the test parameters or test data in the embodiment of the present application are unit tests of functions / methods that are text or can be converted into text (JSON, XML, Text). Such functions / methods include but are not limited to Web site requests, Web APIs and REST APIs, etc., which are not limited here.

[0058] based on Figure 1It can be seen from the illustrated embodiment that in order to test the unit under test, in addition to the test data, the embodiment of the present application also relies on the test entry indicated in the test file. For example, if the unit under test is a class, the test entry of the unit under test is the full name of the class. If the unit under test is a Web API, the test entry of the unit under test is generally the URL of its controller. In addition, the test entry of the embodiment of the present application also includes the function / method entry in the aforementioned class.

[0059] It is understandable that when a unit under test is performed on a unit, it is mainly determined whether the actual output of the unit under test when receiving the test parameters as input is consistent with the corresponding expected results to determine whether the unit under test passes the corresponding unit test. Therefore, the test data of the embodiment of the present application includes the test parameters and the expected results corresponding to the test parameters.

[0060] 202. Call the unit under test based on the test parameters and the test entry to obtain the actual output corresponding to the test parameters.

[0061] After obtaining the test entry of the unit under test, the embodiment of the present application can accurately locate or call the unit under test, and input the test parameters in the test data into the unit under test to obtain the actual output of the unit under test corresponding to the test parameters.

[0062] 203. Determine a test result of the unit under test based on the actual output corresponding to the test parameter and the expected result corresponding to the test parameter.

[0063] Based on the above embodiments, it can be known that the purpose of unit testing is to verify that the behavior of each unit in the software program meets the design requirements. Therefore, the embodiments of the present application need to determine whether the function of the unit under test meets the design requirements based on the actual output corresponding to the test parameters and the expected results corresponding to the test parameters.

[0064] In some specific implementations, a test file of a test unit usually contains multiple groups of test data. In this case, for the test parameters of each group of test data in the test file, the unit test device inputs it into the unit under test and obtains the corresponding actual output. Finally, based on the expected results of each group of test data and the corresponding actual output, it is jointly determined whether the function of the unit under test meets the design requirements.

[0065] It should be noted that, in the process of testing the unit under test, in addition to considering whether the unit under test can correctly handle the test scenario of abnormal parameters, it is also necessary to consider whether the test unit can correctly handle the test scenario of normal parameters. For example, the function of a unit under test is to judge whether it is an adult based on whether the age of a person is greater than 18, then the tests that need to be performed include but are not limited to: whether the actual output of the unit under test meets expectations when the age is less than zero (such as: -1), greater than 18 (such as: 19), less than 18 (such as: 17) and equal to 0 or equal to 18. Therefore, if the test file of the embodiment of the present application contains multiple groups of test data, each group of test data corresponds to a different test scenario.

[0066] In the embodiment of the present application, a unit test method and a unit test device driven by test data are provided to greatly reduce or even eliminate the need to write unit test code. The reason why the embodiment of the present application is feasible is that the test entry of the unit to be tested is determined prior to the implementation of the unit to be tested, that is, the test entry is generally basically determined before the coding of the unit to be tested begins, so the test data can be prepared after the test entry is determined. On this basis, the developer only needs to configure the corresponding test files for different units to be tested, and the unit test for the unit to be tested can be uniformly and automatically performed through the unit test method of the embodiment of the present application, and the corresponding test results are obtained, without the need for the developer to manually write test cases separately for whether the behavior to be tested under different specific conditions meets expectations, thereby improving the overall test efficiency.

[0067] In some specific implementations, the aforementioned step 203 can be specifically implemented in the following ways: determining a target determination strategy corresponding to the unit under test; and determining a test result of the unit under test based on the target determination strategy, actual output corresponding to the test parameters, and expected results corresponding to the test parameters.

[0068] The embodiment of the present application can configure a variety of different result determination strategies, and at least one of them can be used as the target determination strategy corresponding to the unit under test. It is understandable that the target determination strategy corresponding to the unit under test can be preset in advance, such as pre-set according to the different behaviors to be tested corresponding to the unit under test or the test; it can also be determined in real time, such as pre-configuring corresponding result determination strategies for different actual outputs that may appear in various test units. In actual application, it can be determined according to the actual output corresponding to the test parameters to determine which result determination strategy is suitable for the unit under test. Finally, the actual output corresponding to the test parameters and the expected results corresponding to the test parameters are analyzed in combination with the determined target determination strategy to obtain the test results of the unit under test.

[0069] Furthermore, considering that in actual applications, the actual output of the unit under test may be consistent with or different from the expected result, and any error that causes program interruption may be encountered during the operation of the unit under test or the processing of test parameters, the actual output of the unit under test is actually the error thrown by the unit under test. In order to accurately identify various possible thrown errors, the target determination strategy corresponding to the unit under test in the embodiment of the present application can be determined in the following way: if the actual output corresponding to the test parameter belongs to the normal return of the unit under test, the target determination strategy corresponding to the unit under test is determined from the normal determination strategy; if the actual output corresponding to the test parameter belongs to the thrown error of the unit under test, the target determination strategy corresponding to the unit under test is determined from the abnormal determination strategy.

[0070] Specifically, the normal return of the unit under test referred to in the embodiment of the present application means that the unit under test does not encounter any error that causes program interruption during execution (such as throwing an exception, execution failure, etc.). This situation shows that the execution of the function is smooth and does not trigger any exception handling mechanism. The throwing error of the unit under test referred to in the embodiment of the present application means that the unit under test encounters some abnormal situation or error during execution, causing the unit under test to be unable to complete the task as expected, and notifies the caller of an error through an error handling mechanism (such as throwing an exception, returning an error code, etc.).

[0071] In summary, the embodiment of the present application determines a target determination strategy for the unit under test from different result determination strategies when the actual output of the unit under test belongs to different situations such as normal return or throwing an error, so as to better adapt to the test result determination under various outputs of the unit under test.

[0072] In another implementation, in addition to determining the target judgment strategy corresponding to the unit under test based on the test parameters or the actual output corresponding to the test parameters, corresponding preset judgment strategies can also be uniformly configured in advance for different units under test in the test entry or all units under test in the same test entry, and different priorities can be assigned to the preset judgment strategies configured at different levels.

[0073] If the priority of the preset judgment strategy corresponding to the unit to be tested in the embodiment of the present application is higher than the preset judgment strategy corresponding to the test entry. Then, if there is no corresponding preset judgment strategy for the unit to be tested, the preset judgment strategy corresponding to the test entry will be used as the target judgment strategy corresponding to the unit to be tested; if there is a corresponding preset judgment strategy for the unit to be tested, the preset judgment strategy corresponding to the unit to be tested will be used as the target judgment strategy corresponding to the unit to be tested. Furthermore, the preset judgment strategy in the embodiment of the present application may include a preset normal judgment strategy and a preset abnormal judgment strategy, and different priorities are assigned to normal judgment strategies and preset abnormal judgment strategies of different levels, respectively. The specific configuration can be done as needed and is not limited here.

[0074] For example, the preset normal judgment strategy and the preset abnormal judgment strategy can be applied to a class, function / method or a unit under test in a function / method, with priority from low to high, that is, the priority of the judgment strategy set on the execution unit is higher than the strategy set for the function / method, and the priority of the strategy set for the function / method is higher than the strategy set on the class.

[0075] Furthermore, before the aforementioned step 202, the test file of the embodiment of the present application also includes an initialization unit and initialization parameters corresponding to the initialization unit. The unit testing method of the embodiment of the present application also includes: calling the initialization unit based on the initialization parameters corresponding to the initialization unit; if the initialization unit is called based on the initialization parameters, executing the step of calling the unit to be tested based on the test parameters and the test entry.

[0076] In some test scenarios, one or more initialization units need to be executed before the unit under test runs. Specifically, one or more corresponding initialization units and their corresponding initialization parameters are configured as needed for all test data of the unit under test or at least part of the test data of the unit under test. If there are multiple initialization units, the order in which the multiple initialization units are executed must also be configured, and the initialization is completed according to the order and the corresponding initialization parameters.

[0077] For example, before verifying the data range permission unit, the identity verification unit needs to be executed first, and based on the result of the identity verification operation, it is determined what expected result the data range permission unit should output when the corresponding test parameters are input.

[0078] It should be noted that if there are multiple groups of test data in the test file, then after each test of a group of test data is completed (i.e., after the actual output corresponding to the test parameters in the group of test data is obtained), the unit under test needs to be restored to the state before execution to ensure the smooth progress of subsequent tests. In some specific implementations, the recovery of the unit under test can be achieved through one or more recovery units, which is not limited in the embodiments of the present application.

[0079] The above describes various implementations of the test method of this application. Figure 1 The content shown illustrates various result determination strategies of the embodiments of the present application.

[0080] 1. Normal Judgment Strategy

[0081] ① Direct comparison. Applicable to scenarios where the actual output is returned and the actual output is not large. Determine the test result of the unit under test based on whether the actual output is consistent with the expected result. If they are consistent, the test passes; if they are inconsistent, the test fails.

[0082] ② Digest comparison. Use any digest algorithm to digest the result and compare the digest of the result. This is suitable for scenarios where the actual output is returned and the actual output is large. Specifically, obtain the actual digest value of the actual output and the expected digest value of the expected result; determine the test result of the unit under test based on whether the actual digest value and the expected digest value are consistent. If they are consistent, the test passes; if they are inconsistent, the test fails.

[0083] ③ Adaptive comparison, set the maximum allowable actual output, automatically judge based on the pre-set maximum output threshold, use strategy ② when it is greater than the maximum output threshold, and use strategy ① when it is not greater than the maximum output threshold. The specific configuration can be made as needed and is not limited in this application.

[0084] ④ External verification. Complete the result verification through other verification units. For example, returning the actual output does not completely guarantee that the test has passed. For example, a unit under test that deletes data returns successfully, but it cannot guarantee whether the data is really deleted. It is best to verify the result through a verification unit such as a query unit to ensure that the data is really deleted. Specifically, one or more verification units can be specified for result verification.

[0085] ⑤Combined judgment: Adaptive comparison plus external verification, that is, executing strategy ③ and strategy ④ at the same time.

[0086] 1. Abnormality determination strategy

[0087] ① Expected exceptions. Analyze the actual output of exceptions that may occur in different test scenarios, obtain the expected exceptions that may occur in various test scenarios, and when the expected exceptions are met, determine that the test of the unit under test fails and meets the aforementioned expected exceptions. For example, in the permission test scenario, the expected result is A, but the actual output is A+B, which means that the unit under test outputs content that should not be output, which is an unauthorized exception.

[0088] ② Unexpected exceptions. If any of the expected exceptions are not met, the unit test will be directly judged as not passing to avoid missing possible exceptions.

[0089] It should be noted that the above result determination strategy is only an exemplary description of the present application, and is not a limitation on the result determination strategy of the present application.

[0090] A second aspect of an embodiment of the present application provides a unit testing device, including:

[0091] The acquisition unit 301 is used to acquire a test file of the unit to be tested, wherein the test file includes a test entry and test data, wherein the test data includes test parameters and expected results corresponding to the test parameters;

[0092] The test unit 302 is used to call the unit under test based on the test parameters and the test entry to obtain the actual output corresponding to the test parameters;

[0093] The determination unit 303 is used to determine the test result of the unit under test based on the actual output corresponding to the test parameter and the expected result corresponding to the test parameter.

[0094] In a specific implementation, the determination unit 303 is specifically configured to determine a target determination strategy corresponding to the unit under test; and determine a test result of the unit under test based on the target determination strategy, actual output corresponding to the test parameters, and expected results corresponding to the test parameters.

[0095] In a specific implementation, the result judgment strategy is divided into a normal judgment strategy and an abnormal judgment strategy. The determination unit 303 is specifically used to determine the target judgment strategy corresponding to the unit under test from the normal judgment strategy if the actual output corresponding to the test parameter belongs to the normal return of the unit under test; if the actual output corresponding to the test parameter belongs to the thrown error of the unit under test, then determine the target judgment strategy corresponding to the unit under test from the abnormal judgment strategy.

[0096] In a specific implementation, the determination unit 303 is specifically used to, if there is no corresponding preset judgment strategy for the unit to be tested, use the preset judgment strategy corresponding to the test entry as the target judgment strategy corresponding to the unit to be tested; if there is a corresponding preset judgment strategy for the unit to be tested, use the preset judgment strategy corresponding to the unit to be tested as the target judgment strategy corresponding to the unit to be tested.

[0097] In a specific implementation, if the target determination strategy corresponding to the unit to be tested is a summary comparison strategy, the determination unit 303 is specifically used to obtain an actual summary value of the actual output and an expected summary value of the expected result; based on whether the actual summary value and the expected summary value are consistent, determine the test result of the unit to be tested.

[0098] In a specific implementation, before calling the unit to be tested based on the test parameters and the test entry to obtain the actual output corresponding to the test parameters, the test file also includes an initialization unit and initialization parameters corresponding to the initialization unit. The test unit 302 is also used to call the initialization unit based on the initialization parameters corresponding to the initialization unit; if the initialization unit is called based on the initialization parameters, the step of calling the unit to be tested based on the test parameters and the test entry is executed.

[0099] Figure 4It is a schematic diagram of the structure of a unit test device provided in an embodiment of the present application. The unit test device 400 may include one or more central processing units (CPU) 401 and a memory 405. The memory 405 stores one or more application programs or data.

[0100] The memory 405 may be a volatile storage or a persistent storage. The program stored in the memory 405 may include one or more modules, each of which may include a series of instruction operations in the unit test device. Furthermore, the central processor 401 may be configured to communicate with the memory 405 and execute a series of instruction operations in the memory 405 on the unit test device 400.

[0101] The unit test device 400 may also include one or more power supplies 402, one or more wired or wireless network interfaces 403, one or more input and output interfaces 404, and / or one or more operating systems, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, etc.

[0102] The CPU 401 can execute the aforementioned Figures 1 to 3 The operations performed by the unit testing device in the illustrated embodiment will not be described in detail here.

[0103] It should be noted that, although the steps in the flowcharts involved in the embodiments are drawn in sequence according to the instructions of the arrows, unless otherwise clearly stated in this document, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0104] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0105] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0106] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0107] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0108] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, read-only memory), random access memory (RAM, random access memory), disk or optical disk and other media that can store program code.

[0109] An embodiment of the present application also provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the unit testing method as described above.

Claims

1. A unit testing method, characterized in that: include: Obtain a test file of the unit to be tested, wherein the test file includes a test entry and test data, wherein the test data includes test parameters and expected results corresponding to the test parameters; Calling the unit under test based on the test parameters and the test entry to obtain actual output corresponding to the test parameters; The test result of the unit under test is determined based on the actual output corresponding to the test parameter and the expected result corresponding to the test parameter.

2. The unit testing method according to claim 1, characterized in that: The determining the test result of the unit under test based on the actual output corresponding to the test parameter and the expected result corresponding to the test parameter includes: Determining a target determination strategy corresponding to the unit under test; The test result of the unit under test is determined based on the target determination strategy, the actual output corresponding to the test parameter, and the expected result corresponding to the test parameter.

3. The unit testing method according to claim 2, characterized in that: The result determination strategy is divided into a normal determination strategy and an abnormal determination strategy. The target determination strategy corresponding to the unit under test is determined, including: If the actual output corresponding to the test parameter belongs to the normal return of the unit under test, determining the target determination strategy corresponding to the unit under test from the normal determination strategy; If the actual output corresponding to the test parameter belongs to a thrown error of the unit under test, a target determination strategy corresponding to the unit under test is determined from the exception determination strategy.

4. The unit testing method according to claim 2, characterized in that: The determining of the target determination strategy corresponding to the unit under test includes: If the unit under test does not have a corresponding preset determination strategy, the preset determination strategy corresponding to the test entry is used as the target determination strategy corresponding to the unit under test; If the unit under test has a corresponding preset determination strategy, the preset determination strategy corresponding to the unit under test is used as the target determination strategy corresponding to the unit under test.

5. The unit testing method according to any one of claims 2 to 4, characterized in that: If the target determination strategy corresponding to the unit under test is a summary comparison strategy, determining the test result of the unit under test based on the target determination strategy, the actual output corresponding to the test parameter, and the expected result corresponding to the test parameter includes: Obtaining an actual summary value of the actual output and an expected summary value of the expected result; A test result of the unit under test is determined based on whether the actual digest value is consistent with the expected digest value.

6. The unit testing method according to claim 1, characterized in that: Before calling the unit under test based on the test parameters and the test entry to obtain the actual output corresponding to the test parameters, the test file also includes an initialization unit and initialization parameters corresponding to the initialization unit, and the unit testing method also includes: calling the initialization unit based on the initialization parameters corresponding to the initialization unit; If the initialization unit is called based on the initialization parameter, the step of calling the unit under test based on the test parameter and the test entry is performed.

7. A unit testing device, characterized in that: include: An acquisition unit, used for acquiring a test file of the unit to be tested, wherein the test file includes a test entry and test data, wherein the test data includes test parameters and expected results corresponding to the test parameters; A test unit, used to call the unit under test based on the test parameters and the test entry to obtain an actual output corresponding to the test parameters; A determination unit is used to determine the test result of the unit under test based on the actual output corresponding to the test parameter and the expected result corresponding to the test parameter.

8. A unit testing device, characterized in that: include: CPU, memory and input / output interface; The memory is a transient storage memory or a persistent storage memory; The central processing unit is configured to communicate with the memory and execute instructions in the memory to perform the method according to any one of claims 1 to 6.

9. A computer program product comprising instructions, characterized in that When the computer program product is run on a computer, the computer is caused to execute the method according to any one of claims 1 to 6.

10. A computer storage medium, characterized in that: The computer storage medium stores instructions, and when the instructions are executed on a computer, the computer is caused to execute the method according to any one of claims 1 to 6.