CN117171045A - Unit test method, system, server and storage medium - Google Patents

Unit test method, system, server and storage medium Download PDF

Info

Publication number
CN117171045A
CN117171045A CN202311220604.2A CN202311220604A CN117171045A CN 117171045 A CN117171045 A CN 117171045A CN 202311220604 A CN202311220604 A CN 202311220604A CN 117171045 A CN117171045 A CN 117171045A
Authority
CN
China
Prior art keywords
log
execution
module
function
test
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
CN202311220604.2A
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.)
China Construction Bank Corp
CCB Finetech Co Ltd
Original Assignee
China Construction Bank Corp
CCB Finetech 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 China Construction Bank Corp, CCB Finetech Co Ltd filed Critical China Construction Bank Corp
Priority to CN202311220604.2A priority Critical patent/CN117171045A/en
Publication of CN117171045A publication Critical patent/CN117171045A/en
Pending legal-status Critical Current

Links

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The application provides a unit testing method, a unit testing system, a server and a storage medium. The method comprises the following steps: the log acquisition subsystem triggers a log monitoring module when receiving a monitoring instruction sent by the test subsystem, and monitors whether an execution log is generated in the function execution module based on the log monitoring module; the execution log is generated when the function to be tested executes the test object; the log monitoring module sends a log acquisition instruction to the log transmission module when monitoring the production execution log in the function execution module; the log transmission module is used for acquiring an execution log based on the log acquisition instruction and transmitting the acquired execution log to the log cache module; the unit test module collects the execution log and generates a test result corresponding to the function to be tested based on the execution log. The method of the application improves the efficiency and accuracy of the unit test.

Description

Unit test method, system, server and storage medium
Technical Field
The present application relates to the field of testing technologies, and in particular, to a unit testing method, a system, a server, and a storage medium.
Background
Unit testing refers to testing of individual units of software in isolation from other parts of the program, primarily to quickly verify that the developed code meets expectations.
If the function to be tested is a function without a return value in the unit test, when the function to be tested is subjected to the unit test, the return value cannot be obtained, so that a false assertion is usually carried out on the function to be tested without the return value, or a data correction trace of execution data of the function to be tested is detected, and further, the assertion is carried out through reversely checking corresponding data in a database, so that a test result is obtained.
However, making a false assertion may result in a decrease in test result accuracy; the second mode of inquiring the data modification trace to assert has the advantages of large workload and complex operation, and reduces the efficiency of unit test.
Disclosure of Invention
The application provides a unit testing method, a system, a server and a storage medium, which are used for solving the problems of low unit testing efficiency and low accuracy in the prior art.
In a first aspect, the present application provides a unit testing method, applied to a testing system; the test system comprises a log acquisition subsystem and a test subsystem; the log acquisition subsystem comprises a log monitoring module, a log transmission module and a log acquisition module; the log acquisition subsystem comprises a function execution module and a unit test module; the method comprises the following steps:
The log acquisition subsystem triggers the log monitoring module when receiving a monitoring instruction sent by the test subsystem, and monitors whether an execution log is generated in the function execution module based on the log monitoring module; the execution log is generated when the function to be tested executes the test object;
the log monitoring module sends a log acquisition instruction to the log transmission module when monitoring the production execution log in the function execution module;
the log transmission module is used for acquiring the execution log based on the log acquisition instruction and transmitting the acquired execution log to the log cache module;
and the unit test module acquires the execution log and generates a test result corresponding to the function to be tested based on the execution log.
Optionally, before the log acquisition subsystem triggers the log listening module, the method further includes:
the function execution module acquires the function to be tested and the test object, and generates a function execution environment required by executing the function to be tested in the function execution module;
executing the function to be tested based on the test object in the function execution environment, and generating an execution log corresponding to the function to be tested in the execution process.
Optionally, the monitoring instruction is an instruction sent by the function execution module to the log monitoring module when the function execution environment is generated, so as to trigger the log monitoring module to monitor the function execution module.
Optionally, the log acquisition subsystem further comprises a cache clearing module;
accordingly, before producing the execution log in the function execution module, the method further includes:
the log monitoring module determines whether a history cache log is stored in the function execution module; and if the history cache log exists, the cache clearing module controls the function execution module to delete the history cache log.
Optionally, the generating, based on the execution log, a test result corresponding to the function to be tested includes:
determining whether the execution process of the function to be tested for executing the test object is completed; if yes, collecting the execution log stored in the log cache;
analyzing the execution log to obtain an analysis result, and generating a test result corresponding to the function to be tested based on the analysis result.
Optionally, the generating, based on the analysis result, a test result corresponding to the function to be tested includes:
Determining an execution result field corresponding to the function to be tested based on the analysis result;
and acquiring a preset assertion statement, performing assertion processing based on the assertion statement and the execution result field, and generating a test result corresponding to the function to be tested.
Optionally, after collecting the execution log, the method further includes:
and transmitting the execution log to a control console so as to analyze the execution process of executing the test object by the function to be tested based on the execution log.
In a second aspect, the present application provides a test system; the test system comprises a log acquisition subsystem and a test subsystem; the log acquisition subsystem comprises a log monitoring module, a log transmission module and a log acquisition module; the log acquisition subsystem comprises a function execution module and a unit test module; wherein:
the log monitoring module is used for triggering the log monitoring module when the log acquisition subsystem receives a monitoring instruction sent by the test subsystem and monitoring whether an execution log is generated in the function execution module based on the log monitoring module; the execution log is generated when the function to be tested executes the test object;
The log monitoring module sends a log acquisition instruction to the log transmission module when monitoring the production execution log in the function execution module;
the log transmission module is used for acquiring the execution log based on the log acquisition instruction and transmitting the acquired execution log to the log cache module;
and the unit test module acquires the execution log and generates a test result corresponding to the function to be tested based on the execution log.
In a third aspect, the present application provides a server comprising: a processor, and a memory communicatively coupled to the processor;
the memory stores computer-executable instructions;
the processor executes computer-executable instructions stored in the memory to implement the method as described in the first aspect.
In a fourth aspect, the present application provides a computer-readable storage medium having stored therein computer-executable instructions for performing the method according to the first aspect when executed by a processor.
In a fifth aspect, the application provides a computer program product comprising a computer program which, when executed by a processor, implements the method of the first aspect.
According to the unit testing method, when the execution log generated in the process of executing the test by the function to be tested is monitored, the execution log is immediately collected and sent to the cache module, so that the execution log is analyzed by the cache module, and the test result is obtained by testing and asserting based on the analysis result, the test and asserting processing based on the test result is realized in real time in the test process, the test result is obtained quickly and conveniently, the test accuracy is ensured, and the test efficiency is improved.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the application and together with the description, serve to explain the principles of the application.
FIG. 1 is a schematic diagram of an exemplary embodiment of a unit testing method according to the present application;
FIG. 2 is a flow chart of a unit testing method according to an embodiment of the present application;
FIG. 3 is a flow chart of another unit testing method according to an embodiment of the present application;
FIG. 4 is a schematic diagram of a test system according to the present application;
fig. 5 is a schematic structural diagram of a server according to an embodiment of the present application;
fig. 6 is a block diagram of a server according to an embodiment of the present application.
Specific embodiments of the present application have been shown by way of the above drawings and will be described in more detail below. The drawings and the written description are not intended to limit the scope of the inventive concepts in any way, but rather to illustrate the inventive concepts to those skilled in the art by reference to the specific embodiments.
Detailed Description
Reference will now be made in detail to exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, the same numbers in different drawings refer to the same or similar elements, unless otherwise indicated. The implementations described in the following exemplary examples do not represent all implementations consistent with the application. Rather, they are merely examples of apparatus and methods consistent with aspects of the application as detailed in the accompanying claims.
In practical application, when a unit test is performed on a function to be tested without a return value, in the prior art, due to the fact that conventional assertion cannot be performed, the assertion is abandoned or a false assertion is randomly generated, so that a test result is obtained, or whether correction traces exist in data after the function to be tested is detected, for example, data fields in a database are modified, and then assertion is performed through corresponding data in a contrast database, so that the test result is obtained. In the above embodiments, however, discarding the assertion or making a false assertion may result in a decrease in the accuracy of the test result; the second mode of inquiring the data modification trace to assert has the advantages of large workload and complex operation, and reduces the efficiency of unit test.
The application provides a unit testing method, which aims to solve the technical problems in the prior art. Specifically, when an execution log generated in the execution test process of the function to be tested is monitored by a log acquisition subsystem in the sampling test system, the execution log is automatically acquired immediately; and further, the test subsystem is adopted to analyze the execution log stored in the log acquisition subsystem, test assertion processing is carried out based on the obtained analysis result, a test result is obtained, the test assertion processing is carried out based on the test result in real time in the test process, the test result is obtained quickly and conveniently, the test accuracy is ensured, and the test efficiency is improved.
Fig. 1 is an application scenario diagram of a unit testing method provided by the present application. The application scenario to which the embodiment of the present application is applicable is described below with reference to fig. 1. Referring to fig. 1, the unit testing method provided by the application is applied to a testing system, and in particular, the testing system comprises a log acquisition subsystem 1 and a testing subsystem 2. The log acquisition subsystem comprises a log monitoring module, a log transmission module and a log acquisition module; the log acquisition subsystem comprises a function execution module and a unit test module. Specifically, the function execution module generates a function running environment when acquiring a function to be tested and a test object, and triggers the log monitoring module to monitor the log; further, executing the test object by adopting the function to be tested, and generating an execution log corresponding to the function to be tested in the execution process; further, the log monitoring module monitors whether an execution log exists in the function execution module, and when the execution log exists in the function execution module, the log monitoring module transmits a message to the log transmission module so that the log transmission module can acquire the execution log and transmit the execution log to the log caching module; further, the unit test module obtains an execution log in the log buffer module, analyzes the execution log to obtain an analysis result, determines an execution result field generated in the execution process of the function to be tested from the analysis result, and tests and asserts the execution result field based on a preset assertion statement to generate a test result corresponding to the function to be tested.
The following describes the technical scheme of the present application and how the technical scheme of the present application solves the above technical problems in detail with specific embodiments. The following embodiments may be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments. Embodiments of the present application will be described below with reference to the accompanying drawings.
Fig. 2 is a flow chart of a unit testing method according to an embodiment of the application. The method may be performed by a unit testing device, which may be a server or other devices, and the server is taken as an example to describe the method in this embodiment, and the method may be implemented by software, hardware, or a combination of software and hardware, as shown in fig. 2, and includes the following steps.
S210, the log acquisition subsystem triggers a log monitoring module when receiving a monitoring instruction sent by the test subsystem, and monitors whether an execution log is generated in the function execution module based on the log monitoring module.
In this embodiment, the log collection subsystem may be understood as a system that the test subsystem collects an execution log generated when the function to be tested executes the test object; further, the test subsystem may be understood as a system that performs assertion test processing on the execution log to generate a test result. Specifically, the log acquisition subsystem comprises a log monitoring module; the log monitoring module may be understood as a module for monitoring whether an execution log is generated in the function execution module. Specifically, the test subsystem comprises a function execution module; the function execution module may be understood as an execution module for executing the test object by the function to be tested.
It should be noted that the execution log is a log generated when the function to be tested executes the test object. Specifically, the test object may be a data field or other content stored in a database; the function to be tested can be understood as an operation function for performing operations such as adding, deleting, modifying, checking and the like on the data fields in the database; of course, it may be a function of processing other contents; the technical scheme of the application is not particularly limited to the function to be tested and the type of the test object.
In the application, the function to be tested comprises a function with a return value and a function without a return value. The function to be tested with the return value can be an inquiry function, and the return value is an inquiry result after the inquiry function is executed; the function to be tested without the return value may be a delete function, and after the delete function is executed, the deleted content is not returned, or the deleted content is returned as the return value. Therefore, in the process of testing the function to be tested without the return value, in order to enable the unit test which cannot perform conventional test assertion processing based on the return value to obtain an accurate test result, the technical scheme provided by the embodiment of the application can monitor the execution log in the execution process of the function to be tested, collect the execution log, and further obtain a corresponding execution field result based on the execution log, so that the test assertion processing is performed based on the execution field result to obtain the test result.
It should be noted that, in order to reduce the invalid monitoring operation of the log monitoring module for a long time, the system operation rate is occupied, and the system operation efficiency is reduced, so that the test efficiency of the unit test is reduced. The technical scheme provided by the embodiment of the application can trigger the log monitoring module when the monitoring instruction sent by the test subsystem is received, so that the log monitoring module monitors whether an execution log exists in the function execution module.
It should be noted that, the monitoring instruction is an instruction sent by the function execution module to the log monitoring module when the function execution environment is generated, so as to trigger the log monitoring module to monitor the function execution module.
Specifically, in order to ensure that a monitoring log module can monitor a complete execution log in the process of executing a test object by a function to be tested, and further ensure the accuracy of a subsequent test result, in the technical scheme of the application, when the function execution module generates a function execution environment, namely when the generation of the execution log is not started, a monitoring instruction is sent to a log monitoring module, and the log monitoring module monitors the execution log generated in the function execution module.
It should be further noted that, the function execution environment in the present application may be understood as an execution environment necessary for the execution of the function to be tested. Alternatively, the generating process of the running environment may include: the function execution module acquires the function to be tested and the test object, and generates a function execution environment required by executing the function to be tested in the function execution module.
Specifically, in order for the function to be tested to successfully execute the test object, i.e. perform the unit test, an operation environment required for executing the unit test needs to be generated in advance, which may specifically include, but is not limited to: generating class functions and the like required by the execution of the function to be tested.
Further, after the function execution environment is generated, the function to be tested can be executed based on the test object in the function execution environment, and an execution log corresponding to the function to be tested is generated in the execution process.
Specifically, a function to be tested which needs to be subjected to unit test and a test object corresponding to the function to be tested are obtained. By way of example, the test objects may include, but are not limited to, pre-set Mock objects and entries. Specifically, the test object is executed based on the function to be tested, and an execution log corresponding to the function to be tested is generated in the execution process.
S220, when the log monitoring module monitors the production execution log in the function execution module, a log acquisition instruction is sent to the log transmission module.
In the embodiment of the application, the log monitoring module may send log detection instructions to the function execution module at intervals of a preset time period, and when the feedback instruction corresponding to the detection instructions is an execution log detection instruction, trigger the acquisition unit and send the acquisition instruction to the log transmission module to acquire the execution log generated in the function execution module. Optionally, the function execution module may send a generation instruction to the log monitoring module when generating the execution log corresponding to the function to be tested for the first time, so as to trigger the log monitoring module to generate a log acquisition instruction, thereby realizing log acquisition. Of course, the monitoring process of the log monitoring module and the triggering mode of the acquisition instruction can also be specifically set according to actual conditions, and the application is not particularly limited to this.
S230, the log transmission module collects an execution log based on the log collection instruction and transmits the collected execution log to the log buffer module.
In the embodiment of the application, the log transmission module receives the log acquisition instruction transmitted by the log monitoring module and triggers the acquisition operation based on the log acquisition instruction so as to acquire the execution log generated in the function execution module. Further, after the execution log is collected, the log outgoing module further transmits the collected execution log to the test log buffer module for log storage, so that the subsequent unit test module can obtain the execution log and perform unit test based on the execution log.
It should be noted that, the log transmission module provided in the embodiment of the present application may immediately collect the generated partial log in real time when the execution log of the function to be tested is generated, and generate the partial test result of the function to be tested in real time based on the partial log, so as to achieve the purpose of quickly obtaining the complete test result when all the functions to be tested are executed, thereby improving the test efficiency while ensuring the test accuracy.
The log acquisition subsystem also comprises a cache clearing module; specifically, in order to reduce the storage of invalid logs in the log monitoring module and avoid the influence of the invalid logs on subsequent test results, the technical scheme of the application further comprises: the log monitoring module determines whether a history cache log is stored in the function execution module; and if the history cache log exists, the cache clearing module controls the function execution module to delete the history cache log.
Optionally, in practical application, a history cache log generated by performing a history test on a function to be tested or a history cache log generated when performing a unit test on other functions to be tested may be stored in the function execution module, so as to ensure accuracy of a test result obtained based on the stored execution log at the present time, before a day of collection and execution, the log monitoring module determines whether the history cache log exists in the function execution module; optionally, if the data is determined to exist, the cache clearing module controls to delete the history cache log, so that the accuracy of a subsequent test result is ensured, and invalid utilization of a storage space is avoided. For example, the cache flush module may send a flush delete instruction to the function execution module; and then the function instruction module deletes the history cache log cached in the function instruction module when receiving the deleting instruction.
S240, the unit test module collects an execution log and generates a test result corresponding to the function to be tested based on the execution log.
In the embodiment of the application, in order to quickly and conveniently obtain the test result, the unit test module can acquire the execution log stored in the log buffer module, and when the execution log is acquired, test assertion processing is performed in the unit test module to generate the test result.
Optionally, the method for generating the test result corresponding to the function to be tested based on the execution log in the application specifically includes: determining whether the execution process of the function to be tested to execute the test object is completed; if yes, collecting an execution log stored in a log cache; analyzing the execution log to obtain an analysis result, and generating a test result corresponding to the function to be tested based on the analysis result.
In practical application, the received partial execution log can be analyzed in real time in the execution process of the function to be tested, so that a corresponding analysis result is obtained, and a test result is obtained based on the analysis result. Optionally, in order to ensure accuracy of the analysis result and further ensure accuracy of the subsequent test result, in practical application, whether the monitoring function execution module sends an execution completion instruction when receiving the execution log may also be determined; when receiving the execution completion instruction, performing log analysis operation on all the instructions after the execution completion at the same time to obtain a complete analysis result, and further performing subsequent test assertion processing based on the analysis result to obtain an accurate test result.
Optionally, the method for generating the test result corresponding to the function to be tested based on the analysis result in the technical scheme of the application can include: determining an execution result field corresponding to the function to be tested based on the analysis result; and acquiring a preset assertion statement, performing assertion processing based on the assertion statement and the execution result field, and generating a test result corresponding to the function to be tested.
Specifically, field screening is performed on the analysis result to obtain an execution result field corresponding to the function to be tested. Further, a preset assertion statement is returned, and test assertion processing is carried out on the execution result field based on the assertion statement, so that a test result of the function to be tested is obtained.
In practical application, the control module also needs to acquire an execution log of the function to be tested and analyze the execution process of the function to be tested. Optionally, in an optional implementation manner provided by the technical scheme of the present application, after the execution log is collected, the execution log is transmitted to the console, so as to analyze the execution process of executing the test object on the function to be tested based on the execution log.
Specifically, the log transmission module synchronously transmits the execution log to the control module while transmitting the execution log to the log buffer module for unit test; further, the control module analyzes the execution process of the function to be tested based on the received execution log so as to ensure that the function to be tested is accurately executed in the unit test process, and therefore the accuracy of a subsequently obtained test result is further improved.
In the scheme, a function execution module generates a function running environment when acquiring the function to be tested and the test object, and triggers a log monitoring module to monitor the log; executing the test object by adopting the function to be tested, and generating an execution log corresponding to the function to be tested in the execution process; the log monitoring module monitors whether an execution log exists in the function execution module, and when the execution log exists in the function execution module, the log monitoring module transmits a message to the log transmission module so that the log transmission module can acquire the execution log and transmit the execution log to the log caching module; further, the unit test module obtains the execution log in the log buffer module, analyzes the execution log to obtain an analysis result, determines an execution result field generated in the execution process of the function to be tested from the analysis result, tests and asserts the execution result field based on a preset assertion statement to generate a test result corresponding to the function to be tested, tests and asserts the execution result based on the test result in real time in the test process, and further achieves the purposes of obtaining the test result quickly and conveniently, guaranteeing the test accuracy and improving the test efficiency.
On the basis of the above embodiment, it may also be stated that, when the test object for performing the unit test includes a branch object, executing each branch object by using the function to be tested, and generating a return value of each branch object; in practical application, if the return values of all branch objects are the same, the execution result returned at the later moment can cover the execution result returned at the previous moment; or each branch object does not return an execution result, in this case, an accurate test result cannot be obtained quickly and conveniently based on the prior art. In the above-mentioned technical solution provided by the embodiment of the present application, the execution result fields corresponding to the branch objects may be obtained by the execution log, so as to obtain the final test result of the function to be tested based on the execution result fields, so as to solve the problem in the prior art that the accuracy of the test result is low when the branch objects are tested, and further improve the accuracy of the test result.
Fig. 3 is a flow chart of another unit testing method according to an embodiment of the application. This embodiment may be understood as an exemplary description of the entire testing steps of the unit testing method proposed by the present application, and referring to fig. 3, the method may specifically include:
Step one, a function execution module initializes a test environment for unit test and triggers a log monitoring module; illustratively, class functions and the like required for running the function under test are generated in advance.
Step two, a function execution module acquires a function to be tested and a test object; illustratively, test objects include, but are not limited to, mock objects and entries, and the like.
And step three, the function execution module executes the test object by adopting the function to be tested, and generates an execution Log generated in the execution process based on the Log4J component.
And step four, when the log monitoring module detects that the execution log exists in the function execution module, a log acquisition instruction is sent to the log transmission module.
And fifthly, the log transmission module acquires an execution log and transmits the execution log to the console and the log caching module respectively.
Step six, the unit test module collects the execution log in the log buffer module, analyzes the execution log to obtain an analysis result, and tests and asserts the analysis result to generate a test result.
And step seven, the control console analyzes the execution process of the received execution log to obtain an analysis result.
According to the unit testing method provided by the application, whether the function to be tested with the return value or the function to be tested without the return value is included, or the execution result field can be obtained through analyzing the result when the branch object is executed, and further, the assertion result is generated by testing and asserting the execution result field, so that the accuracy of unit testing is improved; in addition, the unit test method provided by the application immediately and automatically transmits and analyzes the execution log when monitoring the execution log, so that a test result is generated, and the test efficiency of the unit test is improved.
Fig. 4 is a schematic structural diagram of a test system according to the present application. Referring to fig. 4, the test system includes a log acquisition subsystem 410 and a test subsystem 420; the log collecting subsystem 410 comprises a log monitoring module 411, a log transmitting module 412 and a log collecting module 413; the log acquisition subsystem 420 includes a function execution module 421 and a unit test module 422; wherein:
the log monitoring module 411 is configured to trigger the log monitoring module 411 when the log acquisition subsystem 410 receives a monitoring instruction sent by the test subsystem 420, and monitor whether an execution log is generated in the function execution module 421 based on the log monitoring module 411; the execution log is generated when the function to be tested executes the test object;
the log monitoring module 411 sends a log acquisition instruction to the log transmission module 412 when monitoring the production execution log in the function execution module;
the log transmission module 412 collects an execution log based on the log collection instruction and transmits the collected execution log to the log buffer module 413;
the unit test module 422 collects the execution log and generates a test result corresponding to the function to be tested based on the execution log.
Optionally, in the system:
Before the log acquisition subsystem 410 triggers the log monitoring module 411, the function execution module 421 acquires a function to be tested and a test object, and generates a function execution environment required for executing the function to be tested in the function execution module 421;
and executing the function to be tested based on the test object in the function execution environment, and generating an execution log corresponding to the function to be tested in the execution process.
Optionally, the monitoring instruction is an instruction sent by the function execution module to the log monitoring module when the function execution environment is generated, so as to trigger the log monitoring module to monitor the function execution module.
Optionally, the log collection subsystem 410 further includes a cache cleaning module 414;
correspondingly, in the system:
before producing an execution log in the function execution module, the log monitor module 411 determines whether a history cache log is stored in the function execution module 421; if it is determined that the history cache log exists, the cache purge module 414 controls the function execution module 421 to delete the history cache log.
Optionally, the unit testing module 422 is specifically configured to:
determining whether the execution process of the function to be tested to execute the test object is completed; if yes, collecting an execution log stored in a log cache;
analyzing the execution log to obtain an analysis result, and generating a test result corresponding to the function to be tested based on the analysis result.
Optionally, the unit testing module 422 is specifically further configured to: :
determining an execution result field corresponding to the function to be tested based on the analysis result;
and acquiring a preset assertion statement, performing assertion processing based on the assertion statement and the execution result field, and generating a test result corresponding to the function to be tested.
Optionally, the system is further configured to:
after the execution log is collected, the execution log is transmitted to a console so as to analyze the execution process of the test object for executing the function to be tested based on the execution log.
Fig. 5 is a schematic structural diagram of a server according to an embodiment of the present application. As shown in fig. 5, the server of the present embodiment may include:
at least one processor 501; and
a memory 502 communicatively coupled to the at least one processor;
wherein the memory 502 stores instructions executable by the at least one processor 501, the instructions being executable by the at least one processor 501 to cause the server to perform a method as in any one of the embodiments described above.
Alternatively, the memory 502 may be separate or integrated with the processor 501.
The implementation principle and technical effects of the server provided in this embodiment may be referred to the foregoing embodiments, and will not be described herein again.
The embodiment of the application also provides a computer readable storage medium, wherein computer executable instructions are stored in the computer readable storage medium, and when the processor executes the computer executable instructions, the method of any of the previous embodiments is realized.
Embodiments of the present application also provide a computer program product comprising a computer program which, when executed by a processor, implements the method of any of the preceding embodiments.
In the several embodiments provided by the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described device embodiments are merely illustrative, e.g., the division of modules is merely a logical function division, and there may be additional divisions of actual implementation, e.g., multiple modules may be combined or integrated into another system, or some features may be omitted or not performed.
The integrated modules, which are implemented in the form of software functional modules, may be stored in a computer readable storage medium. The software functional modules described above are stored in a storage medium and include instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) or processor to perform some of the steps of the methods of the various embodiments of the application.
It should be appreciated that the processor may be a central processing unit (Central Processing Unit, CPU for short), other general purpose processors, digital signal processor (Digital Signal Processor, DSP for short), application specific integrated circuit (Application Specific Integrated Circuit, ASIC for short), etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of a method disclosed in connection with the present application may be embodied directly in a hardware processor for execution, or in a combination of hardware and software modules in a processor for execution. The memory may comprise a high-speed RAM memory, and may further comprise a non-volatile memory NVM, such as at least one magnetic disk memory, and may also be a U-disk, a removable hard disk, a read-only memory, a magnetic disk or optical disk, etc.
The storage medium may be implemented by any type or combination of volatile or nonvolatile memory devices such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disk. A storage media may be any available media that can be accessed by a general purpose or special purpose computer.
An exemplary storage medium is coupled to the processor such the processor can read information from, and write information to, the storage medium. In the alternative, the storage medium may be integral to the processor. The processor and the storage medium may reside in an application specific integrated circuit (Application Specific Integrated Circuits, ASIC for short). It is also possible that the processor and the storage medium reside as discrete components in a server or master device.
Fig. 6 is a block diagram of a server according to an embodiment of the present application. Referring to fig. 6, server 800 may include one or more of the following components: a processing component 802, a memory 804, a power component 806, a multimedia component 808, an audio component 810, an input/output (I/O) interface 812, a sensor component 814, and a communication component 816.
The processing component 802 generally controls overall operation of the server 800, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations. The processing component 802 may include one or more processors 820 to execute instructions to perform all or part of the steps of the methods described above. Further, the processing component 802 can include one or more modules that facilitate interactions between the processing component 802 and other components. For example, the processing component 802 can include a multimedia module to facilitate interaction between the multimedia component 808 and the processing component 802.
The memory 804 is configured to store various types of data to support operations at the server 800. Examples of such data include instructions for any application or method operating on server 800, contact data, phonebook data, messages, pictures, video, and the like. The memory 804 may be implemented by any type or combination of volatile or nonvolatile memory devices such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disk.
The power supply component 806 provides power to the various components of the server 800. The power components 806 may include a power management system, one or more power sources, and other components associated with generating, managing, and distributing power for the server 800.
The multimedia component 808 includes a screen between the server 800 and the user that provides an output interface. In some embodiments, the screen may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensor may sense not only the boundary of a touch or sliding action, but also the duration and pressure associated with the touch or sliding operation. In some embodiments, the multimedia component 808 includes a front camera and/or a rear camera. When the server 800 is in an operation mode, such as a photographing mode or a video mode, the front camera and/or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have focal length and optical zoom capabilities.
The audio component 810 is configured to output and/or input audio signals. For example, the audio component 810 includes a Microphone (MIC) configured to receive external audio signals when the server 800 is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals may be further stored in the memory 804 or transmitted via the communication component 816. In some embodiments, audio component 810 further includes a speaker for outputting audio signals.
The I/O interface 812 provides an interface between the processing component 802 and peripheral interface modules, which may be a keyboard, click wheel, buttons, etc. These buttons may include, but are not limited to: homepage button, volume button, start button, and lock button.
The sensor assembly 814 includes one or more sensors for providing status assessment of various aspects for the server 800. For example, the sensor component 814 may detect an on/off state of the server 800, a relative positioning of components, such as a display and keypad of the server 800, the sensor component 814 may also detect a change in position of the server 800 or a component of the server 800, the presence or absence of a user's contact with the server 800, an orientation or acceleration/deceleration of the server 800, and a change in temperature of the server 800. The sensor assembly 814 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 814 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 814 may also include an acceleration sensor, a gyroscopic sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
The communication component 816 is configured to facilitate communication between the server 800 and other devices, either wired or wireless. The server 800 may access a wireless network based on a communication standard, such as WiFi,2G, or 3G, or a combination thereof. In one exemplary embodiment, the communication component 816 receives broadcast signals or broadcast related information from an external broadcast management system via a broadcast channel. In one exemplary embodiment, the communication component 816 further includes a Near Field Communication (NFC) module to facilitate short range communications. For example, the NFC module may be implemented based on Radio Frequency Identification (RFID) technology, infrared data association (IrDA) technology, ultra Wideband (UWB) technology, bluetooth (BT) technology, and other technologies.
In an exemplary embodiment, the server 800 may be implemented by one or more Application Specific Integrated Circuits (ASICs), digital Signal Processors (DSPs), digital Signal Processing Devices (DSPDs), programmable Logic Devices (PLDs), field Programmable Gate Arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic elements for executing the methods described above.
In an exemplary embodiment, a non-transitory computer readable storage medium is also provided, such as memory 804 including instructions executable by processor 820 of server 800 to perform the above-described method. For example, the non-transitory computer readable storage medium may be ROM, random Access Memory (RAM), CD-ROM, magnetic tape, floppy disk, optical data storage device, etc.
A non-transitory computer readable storage medium, which when executed by a processor of a server, enables the server to perform the split screen processing method of the server described above.
Other embodiments of the application will be apparent to those skilled in the art from consideration of the specification and practice of the application disclosed herein. This application is intended to cover any variations, uses, or adaptations of the application following, in general, the principles of the application and including such departures from the present disclosure as come within known or customary practice within the art to which the application pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the application being indicated by the following claims.
It is to be understood that the application is not limited to the precise arrangements and instrumentalities shown in the drawings, which have been described above, and that various modifications and changes may be effected without departing from the scope thereof. The scope of the application is limited only by the appended claims.

Claims (11)

1. A unit testing method, which is characterized by being applied to a testing system; the test system comprises a log acquisition subsystem and a test subsystem; the log acquisition subsystem comprises a log monitoring module, a log transmission module and a log acquisition module; the log acquisition subsystem comprises a function execution module and a unit test module; the method comprises the following steps:
The log acquisition subsystem triggers the log monitoring module when receiving a monitoring instruction sent by the test subsystem, and monitors whether an execution log is generated in the function execution module based on the log monitoring module; the execution log is generated when the function to be tested executes the test object;
the log monitoring module sends a log acquisition instruction to the log transmission module when monitoring the production execution log in the function execution module;
the log transmission module is used for acquiring the execution log based on the log acquisition instruction and transmitting the acquired execution log to the log cache module;
and the unit test module acquires the execution log and generates a test result corresponding to the function to be tested based on the execution log.
2. The method of claim 1, wherein prior to the log acquisition subsystem triggering the log listening module, the method further comprises:
the function execution module acquires the function to be tested and the test object, and generates a function execution environment required by executing the function to be tested in the function execution module;
executing the function to be tested based on the test object in the function execution environment, and generating an execution log corresponding to the function to be tested in the execution process.
3. The method of claim 2, wherein the snoop instruction is an instruction sent by the function execution module to the log snoop module when the function execution environment is generated, to trigger the log snoop module to snoop the function execution module.
4. The method of claim 3, further comprising a cache purge module in the log acquisition subsystem;
accordingly, before producing the execution log in the function execution module, the method further includes:
the log monitoring module determines whether a history cache log is stored in the function execution module; and if the history cache log exists, the cache clearing module controls the function execution module to delete the history cache log.
5. The method according to claim 1, wherein the generating the test result corresponding to the function under test based on the execution log includes:
determining whether the execution process of the function to be tested for executing the test object is completed; if yes, collecting the execution log stored in the log cache;
analyzing the execution log to obtain an analysis result, and generating a test result corresponding to the function to be tested based on the analysis result.
6. The method of claim 5, wherein generating the test result corresponding to the function under test based on the parsing result comprises:
determining an execution result field corresponding to the function to be tested based on the analysis result;
and acquiring a preset assertion statement, performing assertion processing based on the assertion statement and the execution result field, and generating a test result corresponding to the function to be tested.
7. The method of any of claims 1-6, wherein after collecting the execution log, the method further comprises:
and transmitting the execution log to a control console so as to analyze the execution process of executing the test object by the function to be tested based on the execution log.
8. A test system; the test system comprises a log acquisition subsystem and a test subsystem; the log acquisition subsystem comprises a log monitoring module, a log transmission module and a log acquisition module; the log acquisition subsystem comprises a function execution module and a unit test module; wherein:
the log monitoring module is used for triggering the log monitoring module when the log acquisition subsystem receives a monitoring instruction sent by the test subsystem and monitoring whether an execution log is generated in the function execution module based on the log monitoring module; the execution log is generated when the function to be tested executes the test object;
The log monitoring module sends a log acquisition instruction to the log transmission module when monitoring the production execution log in the function execution module;
the log transmission module is used for acquiring the execution log based on the log acquisition instruction and transmitting the acquired execution log to the log cache module;
and the unit test module acquires the execution log and generates a test result corresponding to the function to be tested based on the execution log.
9. A server, comprising: a processor and a memory communicatively coupled to the processor;
the memory stores computer-executable instructions;
the processor, when executing the computer-executable instructions, is configured to implement the method of any one of claims 1 to 7.
10. A computer readable storage medium having stored therein computer executable instructions which when executed by a processor are adapted to carry out the method of any one of claims 1 to 7.
11. A computer program product comprising a computer program which, when executed by a processor, implements the method of any of claims 1 to 7.
CN202311220604.2A 2023-09-20 2023-09-20 Unit test method, system, server and storage medium Pending CN117171045A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311220604.2A CN117171045A (en) 2023-09-20 2023-09-20 Unit test method, system, server and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311220604.2A CN117171045A (en) 2023-09-20 2023-09-20 Unit test method, system, server and storage medium

Publications (1)

Publication Number Publication Date
CN117171045A true CN117171045A (en) 2023-12-05

Family

ID=88946577

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311220604.2A Pending CN117171045A (en) 2023-09-20 2023-09-20 Unit test method, system, server and storage medium

Country Status (1)

Country Link
CN (1) CN117171045A (en)

Similar Documents

Publication Publication Date Title
CN111221733A (en) Information processing method and device, mobile terminal and storage medium
CN116069612A (en) Abnormality positioning method and device and electronic equipment
CN113094225B (en) Abnormal log monitoring method and device and electronic equipment
CN112256563A (en) Android application stability testing method and device, electronic equipment and storage medium
CN110213062B (en) Method and device for processing message
CN108228433B (en) Electronic equipment, and method and device for counting visit time and stay time of mobile application
CN117171045A (en) Unit test method, system, server and storage medium
CN114428737A (en) Communication method, device, equipment and storage medium based on micro service system
CN112489653B (en) Speech recognition method, device and storage medium
CN112883314A (en) Request processing method and device
CN113760946A (en) Pre-verification processing method, device, equipment and medium applied to data source migration
CN109947640B (en) Regression test-based core function coverage statistical method and device
CN113407879A (en) Data reporting method, device and readable medium
CN112363917B (en) Application program debugging exception processing method and device, electronic equipment and medium
CN114710401B (en) Abnormality positioning method and device
CN113420205B (en) Method and device for determining shared source account, terminal equipment and server
CN111611156B (en) Function test method, function test device, and computer-readable storage medium
CN115687157B (en) Test method, test system, storage medium, electronic device, and vehicle
CN112733141B (en) Information processing method and device
CN112346968B (en) Automatic detection method and device for definition of multimedia file
CN116828064A (en) Service request time consumption statistics method and device, electronic equipment and storage medium
CN117762766A (en) Application process debugging method and device and electronic equipment
CN115758383A (en) Security analysis method and device and mobile terminal equipment
CN113986648A (en) Method and device for executing application program, electronic equipment and storage medium
CN114201386A (en) Data processing 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