CN113986757A - Test method, test apparatus, electronic device, storage medium, and program product - Google Patents

Test method, test apparatus, electronic device, storage medium, and program product Download PDF

Info

Publication number
CN113986757A
CN113986757A CN202111341749.9A CN202111341749A CN113986757A CN 113986757 A CN113986757 A CN 113986757A CN 202111341749 A CN202111341749 A CN 202111341749A CN 113986757 A CN113986757 A CN 113986757A
Authority
CN
China
Prior art keywords
test
data
test result
current
functional unit
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111341749.9A
Other languages
Chinese (zh)
Inventor
杨乾军
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Dajia Internet Information Technology Co Ltd
Original Assignee
Beijing Dajia Internet 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 Beijing Dajia Internet Information Technology Co Ltd filed Critical Beijing Dajia Internet Information Technology Co Ltd
Priority to CN202111341749.9A priority Critical patent/CN113986757A/en
Publication of CN113986757A publication Critical patent/CN113986757A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3604Software analysis for verifying properties of programs
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Computing Systems (AREA)
  • Tests Of Electronic Circuits (AREA)

Abstract

The disclosure provides a test method, a test device, electronic equipment, a storage medium and a program product, and relates to the technical field of computers. The test method comprises the following steps: acquiring a target code to be tested; performing a first static type test on the functional unit subcodes by using the first test data to obtain a current first test result, and performing a second static type test on the functional unit subcodes by using the second test data to obtain a current second test result; and if the current first test result is determined to be the expected test result corresponding to the first test data and the current second test result is determined to be the expected test result corresponding to the second test data, determining that the static type of the functional unit subcode is correct. The method and the device improve the accuracy of the obtained test result of the static type of the functional unit subcode, and improve the efficiency and accuracy of determining the correctness of the static type of the functional unit subcode.

Description

Test method, test apparatus, electronic device, storage medium, and program product
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a test method, a test apparatus, an electronic device, a computer-readable storage medium, and a computer program product.
Background
In the process of testing the code, in order to optimize the code, certain functional units in the code can be subjected to code reconstruction, and in order to judge whether the code reconstruction destroys the function of the code, the functional units in the code can be tested after the code reconstruction so as to detect the correctness of the business logic and the static type of the functional units in the code.
In the related art, for a written code, before and after the code is reconstructed, a unit test can be performed on a functional unit in the code based on a test framework. However, for the code written in the partial programming language, although the correctness of the business logic of the functional unit in the code can be detected by using the test framework, the correctness of the static type of the functional unit cannot be accurately detected.
Disclosure of Invention
The present disclosure provides a testing method, an apparatus, an electronic device, a storage medium, and a program product, to at least solve the problems in the related art that the specific information of the static type test result of a functional unit cannot be determined, and the efficiency and accuracy of determining the correctness of the static type of the subcode of the functional unit are low. The technical scheme of the disclosure is as follows:
according to a first aspect of embodiments of the present disclosure, there is provided a test method, including:
acquiring an object code to be tested, wherein the object code comprises a functional unit subcode;
performing a first static type test on the functional unit subcodes by using first test data to obtain a current first test result, and performing a second static type test on the functional unit subcodes by using second test data to obtain a current second test result, wherein the data type of the first test data is a data type in which the functional unit subcodes can run, and the data type of the second test data is a data type in which the functional unit subcodes cannot run;
and if the current first test result is determined to be the expected test result corresponding to the first test data and the current second test result is determined to be the expected test result corresponding to the second test data, determining that the static type of the functional unit subcode is correct.
Optionally, determining that the current first test result is the expected test result corresponding to the first test data includes:
if the current first test result is a null array, acquiring first snapshot data, wherein the first snapshot data is snapshot data of a historical first test result;
and if the first snapshot data is a null array, determining that the current first test result is an expected test result corresponding to the first test data.
Optionally, the testing method further includes:
and updating the first snapshot data with the current first test result in response to the updating operation on the first snapshot data.
Optionally, determining that the current second test result is the expected test result corresponding to the second test data includes:
if the current second test result is a non-empty array, second snapshot data is obtained, and the second snapshot data is snapshot data of a historical second test result;
and if the second snapshot data is determined to be the same as the current second test result, determining that the current second test result is the expected test result corresponding to the second test data.
Optionally, the second snapshot data is the same as the current second test result, and includes:
the second snapshot data is a non-empty array, the length of the array corresponding to the second snapshot data is the same as that of the array corresponding to the current second test result, and the character strings in the array corresponding to the second snapshot data are consistent with those in the array corresponding to the current second test result.
Optionally, the testing method further includes:
and updating the first snapshot data with the current second test result in response to the updating operation of the second snapshot data.
Optionally, performing a first static type test on the functional unit subcode by using the first test data to obtain a current first test result, where the method includes:
and running a first test script corresponding to the functional unit subcodes, and calling the functional unit subcodes by using the first test data as a parameter to perform a first static type test to obtain a current first test result.
Optionally, performing a second static type test on the functional unit subcode by using second test data to obtain a current second test result, where the method includes:
and running a second test script corresponding to the functional unit subcodes, and calling the functional unit subcodes by using second test data as a parameter to perform a second static type test to obtain a current second test result.
According to a second aspect of the embodiments of the present disclosure, there is provided a test apparatus including:
the acquisition module is configured to acquire an object code to be tested, wherein the object code comprises a functional unit subcode;
the test module is configured to perform a first static type test on the functional unit subcodes by using first test data to obtain a current first test result, and perform a second static type test on the functional unit subcodes by using second test data to obtain a current second test result, wherein the data type of the first test data is a data type in which the functional unit subcodes can run, and the data type of the second test data is a data type in which the functional unit subcodes cannot run;
and the determining module is configured to determine that the static type of the functional unit subcode is correct if the current first test result is determined to be the expected test result corresponding to the first test data and the current second test result is determined to be the expected test result corresponding to the second test data.
Optionally, the determining module is configured to:
if the current first test result is a null array, acquiring first snapshot data, wherein the first snapshot data is snapshot data of a historical first test result;
and if the first snapshot data is a null array, determining that the current first test result is an expected test result corresponding to the first test data.
Optionally, the apparatus further comprises:
and the updating module is configured to respond to the updating operation of the first snapshot data and update the first snapshot data by using the current first test result.
Optionally, the determining module is configured to:
if the current second test result is a non-empty array, second snapshot data is obtained, and the second snapshot data is snapshot data of a historical second test result;
and if the second snapshot data is determined to be the same as the current second test result, determining that the current second test result is the expected test result corresponding to the second test data.
Optionally, the determining module determines that the second snapshot data is the same as the current second test result, including: the second snapshot data is a non-empty array, the length of the array corresponding to the second snapshot data is the same as that of the array corresponding to the current second test result, and the character strings in the array corresponding to the second snapshot data are consistent with those in the array corresponding to the current second test result.
Optionally, the testing apparatus further includes:
and the updating module is configured to respond to the updating operation of the second snapshot data and update the first snapshot data with the current second test result.
Optionally, the testing module is configured to:
and running a first test script corresponding to the functional unit subcodes, and calling the functional unit subcodes by using the first test data as a parameter to perform a first static type test to obtain a current first test result.
Optionally, the testing module is configured to:
and running a second test script corresponding to the functional unit subcodes, and calling the functional unit subcodes by using second test data as a parameter to perform a second static type test to obtain a current second test result.
According to a third aspect of the embodiments of the present disclosure, there is provided an electronic apparatus including:
a processor;
a memory for storing processor-executable instructions;
wherein the processor is configured to execute the instructions to implement the test method as in the first aspect.
According to a fourth aspect of embodiments of the present disclosure, there is provided a computer-readable storage medium, in which instructions, when executed by a processor of an electronic device, enable the electronic device to perform the testing method of the first aspect.
According to a fifth aspect of embodiments of the present disclosure, there is provided a computer program product comprising a computer program which, when executed by a processor, implements the testing method of the first aspect.
The technical scheme provided by the embodiment of the disclosure at least brings the following beneficial effects:
according to the test method, the test device, the electronic equipment, the storage medium and the program product provided by the embodiment of the disclosure, the functional unit subcode can be tested in a static type mode by using the test data that the functional unit subcode can run to obtain the first test result, and the functional unit subcode can be tested in a second static type mode by using the test data that the functional unit subcode cannot run to obtain the second test result, so that the specific information of the test result of the functional unit subcode in the static type can be automatically obtained without manual determination, and the efficiency of determining the specific information of the test result of the functional unit subcode in the static type is improved; meanwhile, when it is determined that all the functional unit subcodes before and after code reconstruction can operate the executable data type of the functional unit subcodes, and all the functional unit subcodes before and after code reconstruction cannot operate the test data of the non-executable data type of the functional unit subcodes, and the second test results before and after code reconstruction are the same, the static type of the functional unit subcodes is determined to be correct, and the correctness of the static type of the functional unit subcodes can be rapidly determined through two operation results of the functional unit subcodes on the executable data and the non-executable data, so that the efficiency and the accuracy for determining the correctness of the static type of the functional unit subcodes are improved.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the disclosure and are not to be construed as limiting the disclosure.
FIG. 1 is a flow chart illustrating a testing method according to an exemplary embodiment.
FIG. 2 is a flowchart illustrating a method of determining a current first test result as an expected test result corresponding to first test data in accordance with an exemplary embodiment.
FIG. 3 is a flowchart illustrating a method of determining a current second test result as an expected test result corresponding to second test data in accordance with an exemplary embodiment.
FIG. 4 is a flow chart illustrating another testing method according to an exemplary embodiment.
FIG. 5 is a schematic diagram illustrating a configuration of a testing device according to an exemplary embodiment.
Fig. 6 is a schematic structural diagram of an electronic device according to an exemplary embodiment.
Detailed Description
In order to make the technical solutions of the present disclosure better understood by those of ordinary skill in the art, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings.
It should be noted that the terms "first," "second," and the like in the description and claims of the present disclosure and in the above-described drawings are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the disclosure described herein are capable of operation in sequences other than those illustrated or otherwise described herein. The implementations described in the exemplary embodiments below are not intended to represent all implementations consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present disclosure, as detailed in the appended claims.
In the related art, in the test stage of the target code, if the functional unit subcodes in the target unit are reconstructed, the static type and the logicality of the reconstructed functional unit subcodes need to be detected to ensure that the code reconstruction does not damage the functional implementation of the functional unit subcodes. In general, a testing tool may be used to test the correctness of the static type of the function unit subcode, but the testing tool used in the related art can only prompt whether the function unit subcode has a static type error when detecting the static type of the function unit subcode, and cannot determine specific error information. For example, for a functional unit subcode in an object code to be tested, the correctness of the static type of the functional unit subcode may be detected based on a Jest test framework, where the object code may be written in TypeScript programming language, and the process of detecting the correctness of the static type of the functional unit subcode based on the Jest test framework (a code test framework for JavaScript programming language) may include: and adding a JSDoc annotation (JSDoc is a tool for generating an application program interface document of a JavaScript application program or a module according to annotation information in a JavaScript file) to the functional unit subcode, wherein the JSDoc annotation can be an "@ ts-expect-error" instruction, and during the test process of the code to be tested, the JSDoc parser can identify the JSDoc annotation, and if the static type of the functional unit subcode is correct, prompt information of invalid instructions can be displayed, and if the static type of the functional unit subcode is incorrect, prompt information of static type errors can be displayed.
Therefore, the method for detecting the correctness of the static type of the function unit subcode in the target code, which is provided in the related art, simply prompts whether the function unit subcode has a static type error, cannot automatically determine the specific information of the test result of the static type, and needs a tester to determine the specific information of the test result of the static type of the function unit subcode according to the prompt information, which consumes time and labor.
In view of the foregoing problems, the embodiments of the present disclosure provide a testing method, which may be applied to any code testing device, such as a personal computer or a desktop computer, and the embodiments of the present disclosure do not limit this. The testing method can be applied to a link of testing the correctness of the static type of the functional unit subcode in the target code, and the tested target code can be written by using a TypeScript programming language. For object code written by the TypeScript programming language, the code testing process can be implemented based on a testing tool written by a Jest testing framework and a detection engine of the TypeScript programming language, and application scenarios of the testing method include but are not limited to: the test tool responds to the selection operation of the target code to be tested, loads the pre-stored target code to obtain the target code to be tested, and calls a detection engine of a TypeScript programming language to perform code test, wherein the code test process can be realized in a Jest test framework. The test tool may be a tkit/type-test tool written based on Jest test framework.
Fig. 1 is a flowchart illustrating a testing method according to an exemplary embodiment, as shown in fig. 1, the testing method includes the following steps S101 to S103:
in step S101, an object code to be tested is acquired.
In the embodiments of the present disclosure, the object code includes a functional unit subcode, which refers to a code module in the object code for executing a certain task or implementing a certain function.
In step S102, a first static type test is performed on the functional unit subcode using the first test data to obtain a current first test result, and a second static type test is performed on the functional unit subcode using the second test data to obtain a current second test result.
In the embodiment of the present disclosure, the data type of the first test data is a data type in which the functional unit subcode can run, the first static type test refers to that the functional unit subcode runs the first test data, and the current first test result is a test result obtained by performing the first static type test on the functional unit subcode after the code reconstruction by using the first test data; the data type of the second test data is a data type that the functional unit subcode can not run, the second static type test refers to that the functional unit subcode runs the second test data, and the current second test result is a test result obtained by performing the second static type test on the functional unit subcode after the code is reconstructed by using the second test data.
If the functional unit subcode can run the first test data, the first test result does not include an array, and if the functional unit subcode cannot run the first test data, the first test result includes at least one array; similarly, if the functional unit subcode can run the second test data, the second test result does not include an array, and if the functional unit subcode cannot run the second test data, the second test result includes at least one array, the character string in each array may include a plurality of field identifiers and field information corresponding to the field identifiers, and the field identifiers may include: and the error type identifier, the error code identifier, the file name identifier of the target file and the error information identifier are used for recording the specific information of the test result.
In step S103, if it is determined that the current first test result is the expected test result corresponding to the first test data and the current second test result is the expected test result corresponding to the second test data, it is determined that the static type of the functional unit subcode is correct.
In the embodiments of the present disclosure: the expected test result corresponding to the first test data means that the first static type test is respectively carried out on the functional unit subcodes before and after the code reconstruction, and the functional unit subcodes before and after the code reconstruction can run the first test data; the expected test result corresponding to the second test data means that the second static type test is performed on the functional unit subcodes before and after the code reconstruction, the functional unit subcodes before and after the code reconstruction cannot run the second test data, and the arrays in the second test results obtained by performing the second static type test on the functional unit subcodes before and after the code reconstruction are the same.
In summary, according to the testing method provided by the embodiment of the present disclosure, for the functional unit subcode in the target code, the functional unit subcode may be subjected to static type detection by using the test data that the functional unit subcode is executable to obtain a first test result, and the functional unit subcode may be subjected to second static type detection by using the test data that the functional unit subcode is not executable to obtain a second test result, so that specific information of the test result of the functional unit subcode static type can be automatically obtained without manual determination, and the efficiency of determining the specific information of the functional unit subcode static type test result is improved; meanwhile, when it is determined that all the functional unit subcodes before and after code reconstruction can operate the executable data type of the functional unit subcodes, and all the functional unit subcodes before and after code reconstruction cannot operate the test data of the non-executable data type of the functional unit subcodes, and the second test results before and after code reconstruction are the same, the static type of the functional unit subcodes is determined to be correct, and the correctness of the static type of the functional unit subcodes can be rapidly determined through two operation results of the functional unit subcodes on the executable data and the non-executable data, so that the efficiency and the accuracy for determining the correctness of the static type of the functional unit subcodes are improved.
In an alternative embodiment, in step S101, the testing tool may obtain the target code to be tested.
In the embodiment of the present disclosure, the target code includes a functional unit subcode, and the target code may be written by using TypeScript programming language, for example, the functional unit subcode may be a code module corresponding to a function for executing a certain task in the target code.
In an alternative embodiment, the process of the testing tool acquiring the target code to be tested may include: the test tool may obtain the target code to be tested in response to a load operation on the target code pre-stored in the code testing apparatus.
In an alternative embodiment, in step S102, the test tool may perform a first static type test on the functional unit subcode using the first test data to obtain a current first test result, and perform a second static type test on the functional unit subcode using the second test data to obtain a current second test result.
In the embodiment of the present disclosure, the data type of the first test data is a data type in which the functional unit subcode can operate, and the data type of the second test data is a data type in which the functional unit subcode cannot operate. For example, if the data type in which a certain functional unit sub-code can run is number type data, the first test data is number type test data, and the second test data is non-number type test data, for example, the second test data may include string type test data.
It should be noted that, in the embodiment of the present disclosure, for the functional unit subcode, a first test script and a second test script corresponding to the functional unit subcode may be written in advance, where the first test script is configured to perform a first static type test on the functional unit subcode by using first test data to obtain a first test result; the second test script is used for performing a second static type test on the functional unit subcodes by using second test data to obtain a second test result, wherein the test result is stored in an array form, so that specific information of the static type test result for the functional unit subcodes can be visually obtained, the static type test of the corresponding functional unit subcodes can be performed through two test scripts which are written in advance and correspond to different functional unit subcodes, and the test efficiency is improved.
It can be understood that, in the code compiling process, tasks to be executed or functions to be implemented are various, and code modules corresponding to the tasks or functions are also various, for a code module corresponding to each task or function, a first test script and a second test script corresponding to the task or function can be compiled in advance to obtain a test script library, and in the code testing process, the first test script and the second test script corresponding to a functional unit subcode in an object code can be called in the test script library to test the functional unit subcode in the object code to be tested. Each first test script or second test script in the test script library may include a functional unit identifier of a functional unit sub-code that can be tested by the test script library.
In an alternative embodiment, the process of the test tool performing the first static type test on the functional unit subcode by using the first test data to obtain the current first test result may include: and running a first test script corresponding to the functional unit subcodes, and calling the functional unit subcodes by using the first test data as a parameter to perform a first static type test to obtain a current first test result.
The process of running the first test script corresponding to the functional unit subcode may include: determining the functional unit identification of the functional unit subcode, determining a first test script corresponding to the functional unit identification in a test script library according to the functional unit identification to obtain a first test script corresponding to the functional unit subcode, and running the first test script corresponding to the functional unit subcode.
The method includes that a first static type test is performed by calling a functional unit subcode with first test data as a parameter, and a process of obtaining a current first test result can be implemented based on a first test script to improve efficiency of determining the first test result, where the process includes: and running the first test script to enable the first test script to generate first test data, calling the functional unit subcodes by using the first test data, monitoring the running result of the functional unit subcodes on the first test data, and generating a current first test result according to the running result. If the fact that the functional unit subcode is successfully called by the first test data is monitored, generating a current first test result, converting the current first test result into a JSON (JavaScript Object Notification) format, and enabling the current first test result not to include an array; if the monitoring function unit subcode cannot be successfully called by the first test data, generating a current first test result, and converting the current first test result into a JSON format, where the current first test result includes at least one array, a character string in each array may include a plurality of field identifiers and field information corresponding to the field identifiers, and the field identifiers may include: error type identification, error code identification, file name identification of the target file and error information identification.
It should be noted that the process of executing the code includes: assigning a parameter value to the code, so that the code executes the data processing logic therein according to the parameter value to obtain a process of an execution result of the code on the parameter value, where the test data is the parameter value assigned to the code in a code test stage, and the process of calling the functional unit subcode by using the first test data refers to: and assigning the first test data to the functional unit subcodes so that the functional unit subcodes execute the data processing logic therein according to the first test data to obtain an execution result of the first test data.
In an alternative embodiment, the process of the test tool performing the second static type test on the functional unit subcode by using the second test data to obtain the current second test result may include: and running a second test script corresponding to the functional unit subcodes, and calling the functional unit subcodes by using second test data as a parameter to perform a second static type test to obtain a current second test result.
The process of running the second test script corresponding to the functional unit subcode may include: and determining the functional unit identifier of the functional unit subcode, determining a second test script corresponding to the functional unit identifier in the test script library according to the functional unit identifier, obtaining a second test script corresponding to the functional unit subcode, and running the second test script corresponding to the functional unit subcode.
The second static type test is performed by calling the functional unit subcode with the second test data as a parameter, and the process of obtaining the current second test result may be implemented based on the second test script, so as to improve the efficiency of determining the second test result, where the process may include: and running the second test script to enable the second test script to generate second test data, calling the functional unit subcodes by using the second test data, monitoring the running result of the functional unit subcodes on the second test data, and generating a current second test result according to the running result. If the fact that the functional unit subcode is successfully called by the second test data is monitored, generating a current second test result, and converting the current second test result into a JSON format, wherein the current second test result does not include an array; if the monitoring function unit subcode cannot be successfully called by the second test data, generating a current second test result, and converting the current second test result into a JSON format, where the current second test result includes at least one array, and the character string in each array may include a plurality of field identifiers and field information corresponding to the field identifiers, where the field identifiers may include: error type identification, error code identification, file name identification of the target file and error information identification.
Similarly, the process of calling the functional unit subcode by using the second test data refers to: and assigning the second test data to the functional unit subcodes so that the functional unit subcodes execute the data processing logic therein according to the second test data to obtain an execution result of the second test data.
For example, assume that performing the second static Type test on a functional unit subcode results in a current second test result being { "category":1, "code":2322, "fileName": cmSamples/testcmfail.ts "," messageText ": Type's available to Type ' string ' } ], wherein the current second test result includes an array {" category ":1," code ":2322," enfile ": cmSamples/testcmfail.ts", "messageText": Type's ' Type ' string ' }, the category in the array represents an error Type identifier, and 1 represents an error Type; code represents an error code identification, and 2322 represents an error code; fileName represents the file name identifier of the target file, and cmSamples/testcmfail.ts represents the file name of the target file; the messageText indicates an error information flag, and the Type 'number' is not associated to Type 'string' indicates error information. The current second test result indicates that the functional unit subcode of the target code with the file name cmSamples/testcmfail.ts has a TS2322 error with an error type of 1, and the error information is that the functional unit subcode which can run the data of 'number' type cannot run the data of 'string' type.
In an optional embodiment, in step S103, if the test tool determines that the current first test result is the expected test result corresponding to the first test data and determines that the current second test result is the expected test result corresponding to the second test data, it is determined that the static type of the functional unit subcode is correct.
In the embodiment of the present disclosure, if the current first test result is a null array, it indicates that the functional unit subcode can successfully run the test data of the data type that it can run; and the historical first test result is a null array, which indicates that the functional unit subcodes before code reconstruction can also successfully run test data of the data type in which the functional unit subcodes can run, and can determine that the current first test result is an expected test result corresponding to the first test data, wherein the current first test result is a test result obtained by performing a first static type test on the functional unit subcodes after code reconstruction by using the first test data, and the historical first test result is a first test result obtained by performing a first static type test on the functional unit subcodes before code reconstruction by using the first test data.
If the current second test result is a non-empty array, the functional unit subcode cannot successfully run the test data of the non-executable data type; and the historical second test result is a non-empty array, which indicates that the functional unit subcodes before code reconstruction cannot successfully run the test data of the data type in which the functional unit subcodes cannot run, and then the current second test result can be determined to be an expected test result corresponding to the second test data, wherein the current second test result is a test result obtained by performing a second static type test on the functional unit subcodes after code reconstruction by using the second test data, and the historical second test result is a second test result obtained by performing a second static type test on the functional unit subcodes before code reconstruction by using the second test data.
In an alternative embodiment, as shown in fig. 2, the process of the test tool determining that the current first test result is the expected test result corresponding to the first test data may include the following steps S201 to S203:
step S201, determine whether the current first test result is an empty array.
In an alternative embodiment, the process of the test tool determining whether the current first test result is an empty array may include: acquiring a current first test result, judging whether an array exists in the current first test result, if the array exists in the current first test result, determining that the current first test result is a non-empty array, indicating that the functional unit subcode can not run the data of the data type which can be run by the functional unit subcode, and displaying prompt information of the failure of the static type test of the functional unit subcode and ending the process if the static type of the functional unit subcode is damaged by code reconstruction; if the array does not exist in the current first test result, it is determined that the current first test result is an empty array, which indicates that the functional unit subcode cannot run the data of the data type that can be run, and then the step S202 is continuously executed.
For example, the process of the test tool determining whether the current first test result is an empty array may be implemented by calling a tohavelength (number) matcher, where the tohavelength (number) matcher is configured to determine the number of arrays in the test result; if the current first test result is [ { … }, { … } ], because the current first test result comprises two arrays { … }, the current first test result output by the toHave Length (number) matcher is toHave Length (2), which indicates that the current first test result is a non-null array; if the current first test result is [ ], because no array exists in the current first test result, the current first test result output by the toHaveLength (number) matcher is toHaveLength (0), which indicates that the current first test result is a null array.
Step S202, if the current first test result is a null array, first snapshot data is obtained.
In this embodiment of the present disclosure, the snapshot data is backup data of the test result, the first snapshot data is snapshot data of a historical first test result, and the generating process of the first snapshot data may include: in the process of performing the static type test on the functional unit subcode before code reconstruction, after performing the first static type test on the functional unit subcode before code reconstruction by using the first test data to obtain a first test result, a snapshot data file of the first test result can be generated to obtain first snapshot data.
In an alternative embodiment, the process of the test tool acquiring the first snapshot data may include: first snapshot data is obtained in a snapshot data file.
Step S203, if the first snapshot data is an empty array, determining that the current first test result is an expected test result corresponding to the first test data.
In an alternative embodiment, the process of the test tool determining whether the current first test result is the expected test result corresponding to the first test data may include: the test tool can compare the first snapshot data with a current first test result, and judge whether the first snapshot data is also a null array, if the first snapshot data is the null array, the data indicates that the functional unit subcode before code reconstruction can successfully run the executable data type of the functional unit subcode, and then the current first test result can be determined to be an expected test result corresponding to the first test data; if the first snapshot data is a non-empty array, which indicates that the functional unit subcode cannot run the data of the data type in which the functional unit subcode can run, and the code reconstruction destroys the static type of the functional unit subcode, it may be determined that the current first test result is not the expected test result corresponding to the first test data, and the flow may be ended. The process that the test tool determines whether the current first test result is the expected test result corresponding to the first test data can be achieved by calling a tomatchshop () matcher, the tomatchshop () matcher can compare the first snapshot data with the data content of the current first test result, and if the first snapshot data is consistent with the current first test result, the current first test result is determined to be the expected test result corresponding to the first test data.
It should be noted that, in the embodiment of the present disclosure, when it is determined that the current first test result is a non-empty array, the process may be ended, and prompt information indicating that the static type test of the function unit subcode fails is directly displayed, so that waste of data processing resources caused by processes of subsequently acquiring the first snapshot data, determining whether the first snapshot data is an empty array, and the like may be reduced, and efficiency of determining the correctness of the static type of the function unit subcode may be improved.
In an alternative embodiment, as shown in fig. 3, the process of the test tool determining that the current second test result is the expected test result corresponding to the second test data may include the following steps S301 to S303:
step S301, judging whether the current second test result is a non-empty array.
In an alternative embodiment, the process of the test tool determining whether the current second test result is an empty array may include: acquiring a current second test result, judging whether an array exists in the current second test result, if the array does not exist in the current second test result, determining that the current second test result is an empty array, indicating that the functional unit subcode can run data of an inoperable data type, and displaying prompt information of failure of static type test of the functional unit subcode and ending the process if code reconstruction destroys the static type of the functional unit subcode; if the second test result has an array, determining that the second test result is a non-empty array, which indicates that the functional unit subcode cannot run the data of the data type that the functional unit subcode cannot run, and continuing to execute step S202.
For example, the process that the test tool determines whether the current second test result is an empty array may be implemented by calling a toHaveLength (number) matcher, where if the current second test result is [ { … } ], since the current second test result includes an array { … }, the current second test result output by the toHaveLength (number) matcher is toHaveLength (1), which indicates that the current second test result is a non-empty array; if the current second test result is [ ], because no array exists in the current second test result, the current second test result output by the toHaveLength (number) matcher is toHaveLength (0), which indicates that the current second test result is a null array.
Step S302, if the current second test result is a non-empty array, second snapshot data is obtained.
In this embodiment of the present disclosure, the second snapshot data is snapshot data of a historical second test result, and the generating process of the second snapshot data may include: in the process of performing the static type test on the functional unit subcode before code reconstruction, after performing a second static type test on the functional unit subcode before code reconstruction by using second test data to obtain a second test result, a snapshot data file of the second test result can be generated to obtain second snapshot data.
In an alternative embodiment, the process of the test tool acquiring the second snapshot data may include: and acquiring second snapshot data in the snapshot data file.
Step S303, if it is determined that the second snapshot data is the same as the current second test result, determining that the current second test result is the expected test result corresponding to the second test data.
In an alternative embodiment, the process of the test tool determining that the second snapshot data is the same as the current second test result may include: if the second snapshot data is a non-empty array, judging whether the length of an array corresponding to the second snapshot data is the same as that of an array corresponding to the current second test result; if the length of the array corresponding to the second snapshot data is different from the length of the array corresponding to the current second test result, the second snapshot data is determined to be different from the current second test result, the current second test result is determined not to be the expected test result corresponding to the second test data, the process is ended, and the data processing amount can be reduced.
If the length of the array corresponding to the second snapshot data is the same as that of the array corresponding to the current second test result, continuously judging whether the character strings in the array corresponding to the second snapshot data and the array corresponding to the current second test result are consistent; if the character string in the array corresponding to the second snapshot data is consistent with the character string in the array corresponding to the current second test result, it is determined that the second snapshot data is the same as the current second test result, and when it is determined that the specific information of the second snapshot data is consistent with the specific information of the current second test result, it is determined that the second snapshot data is the same as the current second test result, so as to improve the accuracy of determining the correctness of the static type of the functional unit subcode. The process that the test tool judges whether the character strings in the array corresponding to the second snapshot data and the array corresponding to the current second test result are consistent can be achieved by calling a tomatch () matcher, the tomatch () matcher can compare the data contents of the second snapshot data and the current second test result, and if the second snapshot data and the current second test result are consistent, the current second test result is determined to be an expected test result corresponding to the second test data. It can be understood that, if the second snapshot data is a null array, which indicates that the static type of the functional unit subcode before the code is reconstructed is incorrect, a corresponding prompt message may be displayed, where the prompt message may be an error notification prompt message.
It should be noted that, in the embodiment of the present disclosure, when it is determined that the current second test result is a null array, the process may be ended, and it is directly determined that the static type of the function unit subcode is incorrect, which may reduce the waste of data processing resources caused by the subsequent processes of obtaining the second snapshot data, determining whether the second snapshot data is the same as the current second test result, and improving the efficiency of determining the correctness of the static type of the function unit subcode.
In an alternative embodiment, in the disclosed embodiment, if the test tool determines that the static type of the functional unit subcode is incorrect, the static type error prompt information of the function unit subcode can be displayed, a tester can determine whether the current first test result and the current second test result are in accordance with the actual expectation by checking the current first test result and the current second test result, if the current first test result and the current second test result are determined not to be in accordance with the actual expectation, it may be determined that the static type detection fails for the functional unit subcode, and if it is determined that the current first test result and the current second test result meet actual expectations, the first snapshot data and the second snapshot data can be updated, and the test tool can respond to the updating operation of the first snapshot data and update the first snapshot data by using the current first test result; and updating the first snapshot data with the current second test result in response to the update operation on the second snapshot data.
The process of updating the first snapshot data with the current first test result may include: determining a storage position of the first snapshot data, and replacing the first snapshot data in the storage position of the first snapshot data with a current first test result; the process of updating the first snapshot data with the current second test result may include: and determining the storage position of the second snapshot data, and replacing the second snapshot data in the storage position of the second snapshot data with the current second test result.
In an alternative embodiment, the test tool may receive a snapshot update instruction, update the first snapshot data to the current first test result in response to the snapshot update instruction, and update the second snapshot data to the current second test result. It can be understood that, after the functional unit subcode in the target code is reconstructed again, the correctness of the static type of the functional unit subcode reconstructed again can be judged by using the test result and the updated snapshot data in the next code test process.
For example, assuming that a test tool written based on a Jest test framework is tkit/type-test, an object code to be tested is written using a TypeScript programming language, a file name of the object code is test.ts, the object code test.ts includes a functional unit sub-code T1 corresponding to a function for executing a certain task or implementing a certain function, and the functional unit sub-code T1 needs to be tested, where the data type that the functional unit sub-code T1 can run is a number type, as shown in fig. 4, the process may include:
s401, a test tool tkit/type-test obtains a target code test.ts to be tested;
step S402, a test tool tkit/type-test calls a TypeScript detection engine;
step S403, the test tool tkit/type-test runs a first test script ok.ts corresponding to the functional unit subcode T1 based on the TypeScript detection engine, and calls the functional unit subcode T1 with the first test data '1' as a parameter to perform a first static type test to obtain a current first test result A1; running a second test script corresponding to the functional unit subcode T1, and calling the functional unit subcode T1 by taking second test data "string" as a parameter to perform a second static type test to obtain a current second test result A2;
step S404, the test tool tkit/type-test calls toHaveLength (number) matcher to judge whether the current first test result A1 is an empty array or not and judge whether the current second test result A2 is a non-empty array or not;
step S405, if the current first test result a1 is an empty array and the current second test result a2 is a non-empty array, the test tool tkit/type-test calls the tomatchnapshot () matcher to determine that the first snapshot data a1 ' is also an empty array, and determines that the second snapshot data a2 ' is also a non-empty array, and the non-empty array of the second snapshot data a2 ' is consistent with the character string in the non-empty array of the current second test result a2, and then determines that the static type of the functional unit subcode is correct.
Step S406, if the test tool tkit/type-test determines that the static type of the functional unit subcode is incorrect, the static type error prompt information of the functional unit subcode can be displayed.
In the embodiment of the present disclosure, a tester may check the current first test result and the current second test result based on the static type error prompt information of the functional unit subcode, determine whether the current first test result and the current second test result meet actual expectations, and input a snapshot update instruction in the test tool if the current first test result and the current second test result meet the actual expectations.
In step S407, after the test tool tkit/type-test receives the snapshot update command, the first snapshot data a1 'is updated to the current first test result a1 in response to the snapshot update command, and the second snapshot data a 2' is updated to the current second test result a 2.
FIG. 5 is a block diagram illustrating a testing device according to an exemplary embodiment. Referring to fig. 5, the testing apparatus 500 includes an obtaining module 501, a testing module 502, and a determining module 503.
An obtaining module 501, configured to obtain an object code to be tested, where the object code includes a functional unit subcode;
a test module 502 configured to perform a first static type test on the functional unit subcode by using first test data to obtain a current first test result, and perform a second static type test on the functional unit subcode by using second test data to obtain a current second test result, where the data type of the first test data is a data type in which the functional unit subcode can operate, and the data type of the second test data is a data type in which the functional unit subcode cannot operate;
the determining module 503 is configured to determine that the static type of the functional unit subcode is correct if it is determined that the current first test result is the expected test result corresponding to the first test data and it is determined that the current second test result is the expected test result corresponding to the second test data.
Optionally, the determining module 503 is configured to:
if the current first test result is a null array, acquiring first snapshot data, wherein the first snapshot data is snapshot data of a historical first test result;
and if the first snapshot data is a null array, determining that the current first test result is an expected test result corresponding to the first test data.
Optionally, as shown in fig. 5, the testing apparatus 500 further includes:
an updating module 504 configured to update the first snapshot data with the current first test result in response to an updating operation on the first snapshot data.
Optionally, the determining module 503 is configured to:
if the current second test result is a non-empty array, second snapshot data is obtained, and the second snapshot data is snapshot data of a historical second test result;
and if the second snapshot data is determined to be the same as the current second test result, determining that the current second test result is the expected test result corresponding to the second test data.
Optionally, the determining module 503 determines that the second snapshot data is the same as the current second test result, and includes: the second snapshot data is a non-empty array, the length of the array corresponding to the second snapshot data is the same as that of the array corresponding to the current second test result, and the character strings in the array corresponding to the second snapshot data are consistent with those in the array corresponding to the current second test result.
Optionally, the updating module 504 is configured to update the first snapshot data with the current second test result in response to an update operation on the second snapshot data.
Optionally, the testing module 502 is configured to:
and running a first test script corresponding to the functional unit subcodes, and calling the functional unit subcodes by using the first test data as a parameter to perform a first static type test to obtain a current first test result.
Optionally, the testing module 502 is configured to:
and running a second test script corresponding to the functional unit subcodes, and calling the functional unit subcodes by using second test data as a parameter to perform a second static type test to obtain a current second test result.
With regard to the apparatus in the above-described embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be elaborated here.
Exemplary embodiments of the present disclosure also provide an electronic device, which may be a code testing device. The electronic device is explained below with reference to fig. 6. It should be understood that the electronic device is described below with reference to fig. 6. It should be understood that the electronic device 600 shown in fig. 6 is only one example and should not bring any limitations to the functionality or scope of use of the embodiments of the present disclosure.
As shown in fig. 6, the electronic device 600 is embodied in the form of a general purpose computing device. The components of the electronic device 600 may include, but are not limited to: at least one processing unit 610, at least one memory unit 620, and a bus 630 that couples the various system components including the memory unit 620 and the processing unit 610.
Where the memory unit stores program code, the program code may be executed by the processing unit 610 such that the processing unit 610 performs the steps according to various exemplary embodiments of the present invention as described in the above-mentioned "exemplary methods" section of this specification. For example, processing unit 610 may perform method steps, etc., as shown in fig. 2.
The storage unit 620 may include volatile storage units such as a random access memory unit (RAM)621 and/or a cache memory unit 622, and may further include a read only memory unit (ROM) 623.
The storage unit 620 may also include a program/utility 624 having a set (at least one) of program modules 625, such program modules 625 including, but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which, or some combination thereof, may comprise an implementation of a network environment.
The bus 630 may include a data bus, an address bus, and a control bus.
The electronic device 600 may also communicate with one or more external devices 700 (e.g., keyboard, pointing device, bluetooth device, etc.), which may be through input/output (I/O) interface 640. The electronic device 600 may also communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network, such as the internet) via the network adapter 650. As shown, the network adapter 650 communicates with the other modules of the electronic device 600 via the bus 630. It should be appreciated that although not shown in the figures, other hardware and/or software modules may be used in conjunction with the electronic device 600, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, among others.
It should be noted that although in the above detailed description several modules or units of the device for action execution are mentioned, such a division is not mandatory. Indeed, the features and functions of two or more modules or units described above may be embodied in one module or unit, according to exemplary embodiments of the present disclosure. Conversely, the features and functions of one module or unit described above may be further divided into embodiments by a plurality of modules or units.
As will be appreciated by one skilled in the art, aspects of the present disclosure may be embodied as a system, method or program product. Accordingly, various aspects of the present disclosure may be embodied in the form of: an entirely hardware embodiment, an entirely software embodiment (including firmware, microcode, etc.) or an embodiment combining hardware and software aspects that may all generally be referred to herein as a "circuit," module "or" system. Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure disclosed herein. This application is intended to cover any variations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.
In addition, the present disclosure also provides a computer-readable storage medium, wherein when the instructions in the computer-readable storage medium are executed by a processor of the electronic device, the electronic device is enabled to execute the testing method provided by the above embodiment.
In addition, the present disclosure also provides a computer program product, which includes computer instructions, when the computer instructions are run on an electronic device, the electronic device is caused to execute the test method provided in the above embodiment
Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure disclosed herein. This application is intended to cover any variations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.
It will be understood that the present disclosure is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims (10)

1. A method of testing, comprising:
acquiring an object code to be tested, wherein the object code comprises a functional unit subcode;
performing a first static type test on the functional unit subcodes by using first test data to obtain a current first test result, and performing a second static type test on the functional unit subcodes by using second test data to obtain a current second test result, wherein the data type of the first test data is a data type in which the functional unit subcodes can run, and the data type of the second test data is a data type in which the functional unit subcodes cannot run;
and if the current first test result is determined to be the expected test result corresponding to the first test data and the current second test result is determined to be the expected test result corresponding to the second test data, determining that the static type of the functional unit subcode is correct.
2. The method of claim 1, wherein the determining that the current first test result is an expected test result corresponding to the first test data comprises:
if the current first test result is an empty array, acquiring first snapshot data, wherein the first snapshot data is snapshot data of a historical first test result;
and if the first snapshot data is a null array, determining that the current first test result is an expected test result corresponding to the first test data.
3. The method of claim 1, wherein the determining that the current second test result is the expected test result corresponding to the second test data comprises:
if the current second test result is a non-empty array, second snapshot data is obtained, and the second snapshot data is snapshot data of a historical second test result;
and if the second snapshot data is determined to be the same as the current second test result, determining that the current second test result is an expected test result corresponding to the second test data.
4. The testing method of claim 3, wherein the second snapshot data is identical to the current second test result, comprising:
the second snapshot data is a non-empty array, the length of the array corresponding to the second snapshot data is the same as that of the array corresponding to the current second test result, and the character strings in the array corresponding to the second snapshot data and the array corresponding to the current second test result are consistent.
5. The method of claim 1, wherein performing the first static type test on the functional unit subcode using the first test data to obtain a current first test result comprises:
and running a first test script corresponding to the functional unit subcodes, and calling the functional unit subcodes to perform a first static type test by using the first test data as a parameter to obtain a current first test result.
6. The method of claim 1, wherein performing the second static type test on the functional unit subcode using the second test data to obtain a current second test result comprises:
and running a second test script corresponding to the functional unit subcodes, and calling the functional unit subcodes to perform a second static type test by using the second test data as a parameter to obtain a current second test result.
7. A test apparatus, comprising:
the system comprises an acquisition module, a test module and a test module, wherein the acquisition module is configured to acquire an object code to be tested, and the object code comprises a functional unit subcode;
the test module is configured to perform a first static type test on the functional unit subcode by using first test data to obtain a current first test result, and perform a second static type test on the functional unit subcode by using second test data to obtain a current second test result, wherein the data type of the first test data is a data type in which the functional unit subcode can run, and the data type of the second test data is a data type in which the functional unit subcode cannot run;
a determining module configured to determine that the static type of the functional unit subcode is correct if it is determined that the current first test result is the expected test result corresponding to the first test data and it is determined that the current second test result is the expected test result corresponding to the second test data.
8. An electronic device, comprising:
a processor;
a memory for storing the processor-executable instructions;
wherein the processor is configured to execute the instructions to implement the testing method of any one of claims 1 to 6.
9. A computer-readable storage medium, wherein instructions in the computer-readable storage medium, when executed by a processor of an electronic device, enable the electronic device to perform the testing method of any of claims 1-6.
10. A computer program product comprising a computer program, characterized in that the computer program realizes the testing method of any one of claims 1 to 6 when executed by a processor.
CN202111341749.9A 2021-11-12 2021-11-12 Test method, test apparatus, electronic device, storage medium, and program product Pending CN113986757A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111341749.9A CN113986757A (en) 2021-11-12 2021-11-12 Test method, test apparatus, electronic device, storage medium, and program product

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111341749.9A CN113986757A (en) 2021-11-12 2021-11-12 Test method, test apparatus, electronic device, storage medium, and program product

Publications (1)

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

Family

ID=79748301

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111341749.9A Pending CN113986757A (en) 2021-11-12 2021-11-12 Test method, test apparatus, electronic device, storage medium, and program product

Country Status (1)

Country Link
CN (1) CN113986757A (en)

Similar Documents

Publication Publication Date Title
US9898387B2 (en) Development tools for logging and analyzing software bugs
CN108388489B (en) Server fault diagnosis method, system, equipment and storage medium
CN114168222B (en) Method and device for acquiring time consumption during starting, terminal equipment and storage medium
CN110058998B (en) Software testing method and device
CN111274154A (en) Automatic testing method, device, equipment and storage medium
CN111240955A (en) Automatic testing method and device for Http interface, storage medium and electronic device
CN103186463B (en) Determine the method and system of the test specification of software
US20190042399A1 (en) Test run control method and apparatus
CN112241360A (en) Test case generation method, device, equipment and storage medium
CN111897727A (en) Software testing method and device, computer equipment and storage medium
CN108572895B (en) Stability test method for automatically checking software and hardware configuration under Linux
CN111694684A (en) Abnormal construction method and device of storage equipment, electronic equipment and storage medium
CN112988578A (en) Automatic testing method and device
CN116893960A (en) Code quality detection method, apparatus, computer device and storage medium
CN113986757A (en) Test method, test apparatus, electronic device, storage medium, and program product
CN115454856A (en) Multi-application security detection method, device, medium and electronic equipment
CN111367796B (en) Application program debugging method and device
CN111176653B (en) Program compiling and packaging method and device, electronic equipment and storage medium
CN113986263A (en) Code automation test method, device, electronic equipment and storage medium
CN108845932B (en) Unit testing method and device of network library, storage medium and terminal
CN112015427A (en) Method and device for building multiple compiling environments and electronic equipment
CN115168175A (en) Program error solving method, device, electronic equipment and storage medium
AU2023201696B2 (en) Method and device for determining coverage in HIL testing, and storage medium
CN113010415A (en) Application program fault diagnosis method and device based on bytecode instrumentation technology
CN114116468A (en) Application testing method and device, electronic equipment and storage medium

Legal Events

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