Software testing method and device, electronic equipment, chip and medium
By combining pytest and Qt Test test units, the problem of low testing efficiency of Qt for Python user interface programs is solved, achieving more efficient test coverage and reducing human errors.
Patent Information
- Application Number
- CN202410330329.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-21
- Publication Date
- 2025-09-23
AI Technical Summary
In the prior art, user interface programs designed using Qt for Python have low testing efficiency and low test coverage, are prone to human and mechanical errors, and are difficult to detect hidden errors.
Combining pytest and Qt Test test units improves test efficiency and coverage by screening and executing test cases, simulating inputs, verifying and generating test reports.
By using pytest and Qt Test to simulate input and generate test reports, test efficiency and coverage are improved, more potential problems are discovered, and human errors are reduced.
Smart Images

Figure CN120687352A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of software testing, and in particular to a software testing method, device, electronic device, chip, and medium. Background Art
[0002] With the widespread use of the Python programming language, Qt for Python is increasingly being used to design user interface programs. In related technologies, testing of this type of program often relies on manually operating the interface to verify software functionality. While this allows for flexible testing based on actual conditions, allowing for comprehensive verification of complex business logic and interface interactions, manual testing requires significant manpower and time, is prone to human error, and is difficult to detect hidden errors in software operation. This leads to low testing efficiency and coverage. Summary of the Invention
[0003] The present disclosure provides a software testing method, device, electronic device, chip and medium to solve the problems of low application software testing efficiency and low test coverage. By combining two test units, screening and executing test cases, simulating the input of test cases, verifying and statistically analyzing test results, the test coverage and test efficiency are improved.
[0004] A first aspect of the present disclosure provides a software testing method, the method comprising:
[0005] Using the first test unit to run a first test case set of the object under test, wherein the first test case set is designed based on the second test unit and includes a specified tag, the object under test is in at least one form of a function, a method, a class, and a file, and the specified tag is a functional type of the object under test;
[0006] Initialize test data using the first test unit, where the test data includes input and output based on the object under test corresponding to the second test unit;
[0007] Testing the first test case set using the test data to obtain a test result;
[0008] The test result is verified, and a test report of the tested object is generated using the first test unit.
[0009] In one embodiment of the present disclosure, testing a first test case set using test data to obtain a test result includes:
[0010] In a designated test environment, test data is used as input for a first test case set, the first test case is run, and a test result is obtained. The designated test environment includes dependencies of the first test unit and the second test unit, where the dependency is at least one of a function, module, or file that supports the normal running of the first test unit and the second test unit.
[0011] In one embodiment of the present disclosure, before verifying the test results, the following steps are included:
[0012] A preset verification rule is obtained, where the preset verification rule includes a verification function and / or assertion verification supported by the second test unit.
[0013] In one embodiment of the present disclosure, verifying the test results and generating a test report of the tested object using the first test unit includes:
[0014] Verify the test results and obtain the test output, which indicates whether the test result has passed or failed the verification;
[0015] If the test output is that the test result passes verification, the first test case, the first test data, and the first test output are recorded by the first test unit, and the test results are analyzed to generate a test report; wherein the first test case is at least one item in the first test case set, the first test data is one of the test data, and the first test result is the output obtained by executing the first test data in the first test case;
[0016] If the test output is that the test result fails verification, the first test case, the first test data and the first verification failure information are recorded in the log file, wherein the first verification failure information is the error information generated when the first test data is executed in the first test case.
[0017] In one embodiment of the present disclosure, before using the first test unit to run the first test case set of the tested object, the method further includes:
[0018] Add a label to the object being tested. The label is used to identify the functional type of the object being tested.
[0019] Based on the tag, a first test case set is screened out from the test case set, wherein the test case set includes the first test case set.
[0020] In one embodiment of the present disclosure, testing the first test case set using test data to obtain a test result further includes:
[0021] The test data is used as the input of the first test case set in random order;
[0022] Execute the first test case set and obtain the test results.
[0023] A second aspect of the present disclosure provides a software testing device, the device comprising:
[0024] A test case running module, configured to use the first test unit to run a first test case set of the object under test, wherein the first test case set is designed based on the second test unit and includes a specified tag, and the object under test is in the form of at least one of a function, a method, a class, and a file;
[0025] A test data initialization module, configured to initialize test data based on the first test unit, the test data including inputs and outputs of the object under test corresponding to the second test unit;
[0026] A testing module, configured to test the first test case set using test data to obtain a test result;
[0027] The verification module is used to verify the test result and generate a test report of the tested object using the first test unit.
[0028] The third aspect embodiment of the present disclosure proposes an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute any one of the methods in the first aspect embodiment of the present disclosure.
[0029] The fourth aspect embodiment of the present disclosure proposes a non-transitory computer-readable storage medium storing computer instructions, characterized in that the computer instructions are used to enable a computer to execute the method in the first aspect embodiment of the present disclosure.
[0030] The fifth embodiment of the present disclosure proposes a computer program product, characterized in that it includes a computer program, which implements the method of any one of the embodiments of the first aspect of the present disclosure when executed by a processor. In summary, according to the software testing method proposed in the present disclosure, a first test case set of the object under test is run using a first test unit, wherein the first test case set is designed based on the second test unit and includes a specified tag, the object under test is in the form of at least one of a function, a method, a class, and a file, and the specified tag is the functional type of the object under test, providing a large number of test cases for software testing; the first test unit is used to initialize test data, and the test data includes inputs and outputs of the object under test corresponding to the second test unit, providing a variety of data inputs for testing the above test cases; the first test case set is tested using the test data to obtain test results, and the test of the first test case set is completed; the test results are verified, and the first test unit is used to generate a test report for the object under test and statistical test indicators. By classifying the test cases according to different specified tags, a large number of test cases are obtained, the test cases of the object under test are executed and a test report is automatically generated, thereby improving the test efficiency; by providing a large number of test inputs in different orders to the object under test, the diversity of the test input is increased and the test coverage is improved.
[0031] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] The accompanying drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute an improper limitation of the present disclosure.
[0033] Figure 1 A flowchart of a software testing method according to an embodiment of the present disclosure;
[0034] Figure 2 This is a flowchart of a GUI software testing method based on pytest and Qt Test according to an embodiment of the present disclosure;
[0035] Figure 3 This is a flowchart of a software testing method based on pytest and QtTest according to an embodiment of the present disclosure;
[0036] Figure 4 A flowchart of an embodiment of the present disclosure for testing a first test case set using test data to obtain a test result;
[0037] Figure 5 This is a flow chart of obtaining preset verification rules according to an embodiment of the present disclosure;
[0038] Figure 6 A flowchart of verifying test results and generating a test report of a tested object using a first test unit according to an embodiment of the present disclosure;
[0039] Figure 7 This is a flowchart of a software testing method based on pytest and Qt Test according to an embodiment of the present disclosure;
[0040] Figure 8 A flowchart for determining a first test case set according to an embodiment of the present disclosure;
[0041] Figure 9 A flowchart of an embodiment of the present disclosure for testing a first test case set using test data to obtain a test result;
[0042] Figure 10 A schematic structural diagram of a software testing device according to an embodiment of the present disclosure;
[0043] Figure 11 It is a block diagram of an electronic device for implementing the software testing method disclosed herein according to an exemplary embodiment. DETAILED DESCRIPTION
[0044] The following describes in detail embodiments of the present disclosure, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout identify the same or similar components or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present disclosure, and should not be construed as limiting the present disclosure.
[0045] First, a brief introduction to the relevant terms in this disclosure is given:
[0046] Qt: For the purposes of this disclosure, it refers to a cross-platform C++ development library primarily used for developing graphical user interface (GUI) programs, but it can also develop command-line user interface (CUI) programs. Qt is an object-oriented framework that uses specialized design patterns to facilitate code reuse and meet the needs of the entire software development cycle, from planning and design to development, testing, and deployment.
[0047] Python: In this disclosure, it refers to an interpreted, high-level, and general-purpose programming language that supports multiple programming paradigms, including procedural, object-oriented, and functional programming, and has a rich library and framework that can easily handle various complex tasks.
[0048] Qt for Python: In this disclosure, Qt officially provides a collection of Python-supported components. Specifically, Qt also provides Python bindings, enabling developers to use Python for GUI programming. This combination provides Python users with even more powerful graphical interface processing capabilities. In particular, PyQt, the Python version of Qt, is widely used in Python GUI design.
[0049] Qt Test: In this disclosure, it refers to the Qt module that supports testing of Qt applications and libraries. It is designed to simplify writing unit tests for Qt-based applications. Qt Test provides all the functionality typically found in a testing framework, and also supports extended testing of graphical user interfaces.
[0050] pytest: This disclosure refers to an open-source Python-based testing framework for writing and executing unit tests, integration tests, and functional tests. It provides a concise and easy-to-use application programming interface (API) that makes test writing and maintenance more efficient.
[0051] This paper aims to address the issues of low test efficiency and coverage in Qt for Python application testing. The test suite is built on Qt Test, which runs test cases and uses Qt Test to simulate input. Pytest counts, filters, configures the execution order, verifies test output, and generates test reports.
[0052] The method proposed in this disclosure is applicable to software testing tasks in a wide range of scenarios. It can be used to automate testing of programs built using different test units. For example, this method can be used for unit testing or functional testing of desktop and mobile applications. The application scenarios are not limited in the embodiments of this disclosure.
[0053] The software testing method provided by the present disclosure is described in detail below with reference to the accompanying drawings.
[0054] Figure 1 FIG. 1 is a flow chart of a software testing method according to an embodiment of the present disclosure. Figure 1 In the embodiment shown, the software testing method includes:
[0055] Step 101: Use the first test unit to run a first test case set of the object under test, wherein the first test case set is designed based on the second test unit and includes a specified tag, the object under test is in at least one form of a function, a method, a class, or a file, and the specified tag is a functional type of the object under test.
[0056] In the present embodiment, the first test unit and the second test unit both refer to the platform, environment, framework or module that supports testing the measurand, and the first test unit is different from the second test unit. Preferably, the first test unit is pytest, and the second test unit is Qt Test. Measurand refers to the functional code module to be tested in software testing, including function, method, class, file, and preferably, measurand is Qt for Python code. The first test case set refers to the code for testing the function or sub-function of the measurand designed based on measurand, with a specified mark, and the specified mark is the functional type of measurand, and the mark is used to represent the test case identified as being used to test a specific measurand in the function, method, class, file in all test case sets. Preferably, all test case sets have the same function, method, class, file, etc. as having the same specified mark. For example, in a test case, function 1 and function 2 are both login functions, so function 1 and function 2 can be used as the function of the same specified mark (corresponding to the login function of measurand). In the test case, class 1 is the registration module, class 2 is the deregistration module, class 3 is the new user class, and class 4 is the user data deletion class. Then class 1 and class 3 can be used as classes with the same specified tag (corresponding to the user addition function of the test object), and class 2 and class 4 can be used as classes with the same tag (corresponding to the user deletion function of the test object). The Qt for Python code of the first test case set is designed based on the QTest class of the Qt Test module. In this step, pytest is used to run the first test case set of the test object.
[0057] Step 102: Initialize test data using the first test unit, where the test data includes input and output of the object under test corresponding to the second test unit.
[0058] In this embodiment, test data refers to data provided for testing the object under test, including Qt Test-based simulation of user input and output to the object under test. For example, Qt controls simulate interface actions such as text filling, drop-down box selection, and action triggering; QTest simulates actions such as left and right mouse button clicks and keyboard presses; uses the QWidget class methods and QTest methods provided by PyQt to simulate user actions on the user interface (UI), such as mouse clicks and keyboard input; or simulates interface waiting. The test data including the Qt Test implementation is initialized based on pytest.
[0059] Step 103: Test the first test case set using the test data to obtain a test result.
[0060] In this embodiment, the test result refers to the result obtained by testing the first test case set using the test data. The first test case set is tested using the test data determined in the above steps as data input to obtain the test result.
[0061] In one implementation of this embodiment, the test data is a mouse click signal, and the test case set is a UI program with many components, including a button, a radiobox, and a checkbox. When the UI program is running, test data is provided, that is, a mouse click test is performed on each component of the UI program. If the button receives a click signal, the button is marked as triggering a press operation. If the button does not receive a click signal, the button is marked as not triggered and the state has not changed. The state of the button after the mouse click operation is used as the test result of the button. If the radiobox is selected by a mouse click, the state of the radiobox is marked as changed and changed to the selected state. Otherwise, the radiobox is kept in an unselected state. The state of the radiobox is used as the test result of the radiobox.
[0062] If the checkbox is selected by clicking the mouse, the selected item of the checkbox is marked, and the item whose state has changed in the checkbox is marked as a state, which is used as test data to test the test result of the checkbox.
[0063] Step 104 : Verify the test result and use the first test unit to generate a test report for the object under test.
[0064] In this embodiment, a test report refers to a document that records the process and results of software testing. This document provides an overview and detailed description of the test results, including information such as test execution status, test coverage, and test results. Secondly, the test report also records the problems found during the test process, as well as the process and results of handling these problems. Based on the test output obtained by verifying the test results, pytest can generate a test report for the object under test.
[0065] In one implementation of this embodiment, the test result verification is performed to confirm whether the mouse trigger event corresponds to the control response. The mouse trigger signal type is captured and compared with the state of the control in the UI program after the mouse trigger event. For example, in Qt, the signal-slot mechanism is used to collect the mouse click signal of a key, and the slot function responds to the signal. If the response matches the mouse single click signal but not the mouse double click signal, the test result verification is passed and the test result is obtained.
[0066] In one implementation of this embodiment, the test data for the test output of each control of the UI program can be analyzed to obtain the robustness of each control. For example, the test output is the number of times the mouse click event is correctly triggered for the button in the UI program, or the number of selected items in the check box, the state of the radio button being selected or released, based on which the effectiveness of the mouse click event in the test data can be obtained. The response success rate of the button click event, the effectiveness of each item in the check box, and the number of radio button state changes can also be obtained. Alternatively, each control can be tested in turn through the mouse click event and the double-click event, and the test results can be verified. Through these data, the execution status, test results, and problem locations of the control can be analyzed, and the coverage rate of the test data for the test cases such as the control can also be obtained. After statistics on the test execution status, test coverage, test results and other information, a test report for each control of the UI program is generated, which helps to determine the test focus and improve test efficiency.
[0067] In one implementation of this embodiment, Figure 2 Flowchart of a GUI software testing method based on pytest and Qt Test according to an embodiment of the present disclosure. Figure 2 As shown, to begin testing the GUI software, first complete the test case design. Test code writing involves simulating user interface actions using Qt controls or Qtest methods as test data. Using pytest, build automated test execution, launch the application, and run the Main window. Verification methods such as assertions are used to check interface operation and display. Test execution logs are then generated to determine if any errors or warnings are present. If none are present, the test terminates. If errors or warnings are present, optimize the Qt interface implementation logic and fix any interface anomalies. Then, perform self-verification of the UI functionality, build automated test execution again, and continue testing until the program is error-free or warning-free.
[0068] In one implementation of this embodiment, Figure 3 Flowchart of a software testing method based on pytest and Qt Test in the embodiment of the present disclosure. Figure 3As shown, start software testing and run the specified test case set through pytest-m{}-vs{target_file} in the command line. Search the test case set based on pytest to filter out the test case set. Use pytest.fixture() and conftest.py to initialize the test data, that is, configure the test data. The test data can be sent to the test case set in a preset order, and some test cases can also be skipped. Define the running environment (testordebug), execute the command to run the test case set according to the Request, and verify it according to the custom verification rules or assert. If the test passes (Pass), use the test report generation tool allure to record the execution report, and record the test cases and test data that failed the verification (Error / Fail) in the test execution log, and display the report.
[0069] In summary, according to the software testing method proposed in the present disclosure, a first test unit is used to run a first test case set of the object under test, wherein the first test case set is designed based on the second test unit and includes a specified tag, and the object under test is in at least one form of a function, a method, a class, and a file, providing a large number of test cases for software testing; the first test unit is used to initialize test data, and the test data includes the input and output of the object under test corresponding to the second test unit, providing a variety of data inputs for testing the above test cases; the first test case set is tested by the test data to obtain the test results, and the test of the first test case set is completed; the test results are verified, and the first test unit is used to generate a test report for the object under test and to count the test indicators. By classifying the test cases according to different specified tags, a large number of test cases are obtained, the test cases of the object under test are executed and a test report is automatically generated, thereby improving the test efficiency; by providing a large number of test inputs in different orders to the object under test, the diversity of the test inputs is increased and the test coverage is improved.
[0070] Figure 4 This is a flowchart of an embodiment of the present disclosure for testing a first test case set using test data to obtain a test result. Figure 4 Yes Figure 1 Further explanation of step 103 is based on Figure 4 The embodiment shown includes the following steps:
[0071] Step 401: In a designated test environment, test data is used as input for a first test case set, and the first test case set is run to obtain test results. The designated test environment includes dependencies of the first test unit and the second test unit. A dependency is at least one of a function, module, or file that supports the normal operation of the first test unit and the second test unit.
[0072] In this embodiment, the designated test environment refers to the software and hardware environment that supports the operation of the test object, for example, the operating system is Windows 10, the Python version is Python 3.9.0, and the hardware processor is an x86 serial processor. Preferably, the designated test environment refers to the software test environment in which the test object is run, including the dependencies of the first test unit and the second test unit, that is, the designated test environment includes all dependencies that support pytest and Qt Test. A dependency refers to at least one of the functions, modules, or files that support the normal operation of the first test unit and the second test unit. For example, if a program needs to use a function or class in a library or module during the compilation process, the program is said to have a compile-time dependency on the library or module. This means that before compiling the program, it is necessary to ensure that all dependent libraries or modules have been installed and can be found by the compiler. The libraries, modules, functions, and classes therein are the dependencies of the program. For another example, if a program needs to call a function or class in a dynamic link library (such as a DLL or SO file) during execution, the program is said to have a runtime dependency on the library. This means that before the program runs, you need to ensure that all dependent libraries have been installed in the appropriate location and can be loaded at runtime. That is, the above-mentioned dynamic link libraries are the dependencies of the program. For example, the dependencies that support pytest and Qt Test include pytest-assume for handling parallel assertions and the Python version of Qt, namely PyQt.
[0073] In this embodiment, the first test case set is tested according to the test data, the first test case set is run, the test results are obtained, and the test of the first test case set is completed. For example, a python development environment is installed in a windows system, the pytest package and the PyQt package are installed in the python environment, and then pytest and Qt Test are imported as a designated test environment. The test case to be tested (python for Qt code) is run, and the QTest class of Qt Test is used to simulate the left and right mouse button clicks, keyboard actions, etc. as test data, and the test case is tested to obtain the output of the test case under different inputs, that is, the test results.
[0074] Figure 5 This is a flowchart of obtaining preset verification rules according to an embodiment of the present disclosure. Figure 5 Yes Figure 1 The instructions before step 104 are based on Figure 5 The embodiment shown includes the following steps:
[0075] Step 501: Obtain preset verification rules, where the preset verification rules include verification functions and / or assertion verification supported by the second test unit.
[0076] In this embodiment, the preset validation rules refer to predefined rules used to compare the test results with the corresponding outputs. These rules include validation functions and / or assertions supported by Qt Test. For example, they can verify whether the checked state of a CheckBox has changed, whether the index label of a ComboBox has changed, whether an interface button has been triggered, or whether keyboard input has been captured. Before verifying the test results, the preset validation rules are obtained.
[0077] In one implementation of this embodiment, the preset verification rule is implemented by the following function:
[0078] COMPARE(str1, str2) is used to compare whether the string str1 and the string str2 are the same;
[0079] QEQUAL(val1, val2) and QNEQUAL(val1, val2) are used to compare whether the values of val1 and val2 are the same.
[0080] For character-type test output, QCOMPARE is used to compare the output string to the expected output string to see if they are completely consistent. If they are consistent, the verification passes; otherwise, the verification fails. QEQUAL and QNEQUAL are used to compare the output of numeric-type test results to see if they are consistent with the expected output number, thereby verifying the test results.
[0081] In this embodiment, the reliability of the test results is ensured by verifying the test results.
[0082] Figure 6 This is a flowchart of an embodiment of the present disclosure for verifying test results and generating a test report for a tested object using a first test unit. Figure 6 Yes Figure 1 The specific description of step 104 is based on Figure 6 The embodiment shown includes the following steps:
[0083] Step 601: Verify the test result and obtain a test output, where the test output indicates whether the test result passes or fails verification.
[0084] In this embodiment, it is determined whether the test result passes the verification.
[0085] In one implementation of this embodiment, the verification can be implemented using QCOMPARE, QEQUAL, QNEQUAL and other methods that are natively supported by Qt. For character type test output, for example, to compare whether the text in the LineEdit text box is consistent with the keyboard input, the following function is used for verification:
[0086] QCOMPARE(str1, str2)
[0087] The text entered into the LineEdit control is used as str1. After the LineEdit text box accepts keyboard input, the keyboard-typed text is captured as str2. This code compares the input content of the LineEdit control with the actual content filled in, thus verifying the test results.
[0088] For data output, for example, to compare the current data in the drop-down list with the actual mouse-selected data, you can use the following function to verify:
[0089] QEQUAL(val1, val2), QNEQUAL(val1, val2).
[0090] If the current data recorded in the drop-down list is val1, and the data selected by the mouse in the drop-down list is val2, QEQUAL(val1, val2) or QNEQUAL(val1, val2) is used to verify whether the two are consistent to determine whether the test result of the drop-down list item selected by the mouse passes the verification.
[0091] In one implementation of this embodiment, Figure 7 Flowchart of a software testing method based on pytest and Qt Test in the embodiment of the present disclosure. Figure 7 As shown, start software testing of the object under test, install the QtTest test dependency third-library, and thus build a test environment. Import the dependent Qt Test third-party library for the test file (test case set), which can be imported using the import method. In the test case set, the test class overrides the pre-function setup method and the post-function teardown method for initialization or cleanup operations. Similarly, in the test case set, for the test class, define test methods (test_*) to test different functions or logics. Use QCOMPARE, QVERIFY or ASSERT assertions in the test method to judge the test results and verify the test results. Execute the static method of the Qt Test class or pytest to run the test, thereby completing the test of the application software based on pytest and Qt Test.
[0092] Step 602: If the test output is that the test result passes the verification, the first test case, the first test data, and the first test output are recorded by the first test unit and the test results are analyzed to generate a test report; wherein the first test case is at least one item in the first test case set, the first test data is one of the test data, and the first test result is the output obtained by executing the first test data in the first test case.
[0093] In this embodiment, the first test case refers to at least one item in the first test case set, that is, at least one function, method, class, or file in the first test case set. The first test data refers to a set of data in the test data. The first test result refers to the output obtained by executing the first test case with the first test data input.
[0094] If the test output passes verification, pytest records the first test case, the first test data, and the first test output, analyzes the test results, and generates a test report. Optionally, Allure, a test reporting tool, analyzes the test results to generate a test report. The report includes metrics such as the pass rate of the first test case set for the tested object and the effectiveness of the same test case for different tested objects.
[0095] Step 603: If the test output is that the test result fails verification, the first test case, the first test data and the first verification failure information are recorded in the log file, wherein the first verification failure information is the error information generated when the first test data is executed in the first test case.
[0096] In this embodiment, the first test failure information refers to error information generated when the first test data is input into the first test case and executed, reporting an error or an alarm.
[0097] If the test output fails verification, the first test case, the first test data, and the first verification failure information are recorded in a log file and displayed on the console.
[0098] In this embodiment, based on the test output, a test report of the tested object is generated by the first test unit, and test indicators are counted, thereby providing a data-level analysis basis for improving test efficiency and test coverage.
[0099] Figure 8 This is a flowchart of determining a first test case set according to an embodiment of the present disclosure. Figure 8 Yes Figure 1 The description before step 101 is based on Figure 8 The embodiment shown includes the following steps:
[0100] Step 801: Add a label to the object under test, where the label is used to identify the functional type of the object under test.
[0101] In this embodiment, a label is an identifier for the object under test, used to identify the functional type of the object under test. It can be a string, a number, or a custom attribute of the object under test. To facilitate the reuse of test cases and to test multiple functions using a single test case, labels are added to the object under test for classification. According to this identification method, labels are added to all code modules involved in the test case set for the object under test.
[0102] In one implementation of this embodiment, a label is added to the tested function through a Python code segment of the tested object, such as a function, using a Python decorator. The label is used to identify the function or category of the function.
[0103] The function under test can be represented by the following code:
[0104]
[0105]
[0106] Step 802: Filter out a first test case set from the test case set based on the tag, wherein the test case set includes the first test case set.
[0107] In this embodiment, based on the label added to the object under test, the first test case set can be screened out from all test case sets.
[0108] In one implementation of this embodiment, when the object under test is a function, a decorator is added to the object under test in the Python code to determine its test purpose. According to the above step 801, a decorator is added to the function under test, and a label is added to the function under test to distinguish different function types. When testing a function such as an output function decorator, by indexing the label "output function decorator" in the test, only the two output functions test_func5 and test_func6 can be tested, without having to test test_func1, test_func2, test_func3 and test_func4. Similarly, by indexing the label "operation function decorator" in the test, only the four operation functions of addition, subtraction, multiplication and division, test_func1, test_func2, test_func3 and test_func4, can be tested, without having to test the output function.
[0109] In this embodiment, before using the first test case set to test the object under test, the first test case set is determined to provide dedicated test cases for testing the object under test.
[0110] Figure 9This is a flowchart of an embodiment of the present disclosure for testing a first test case set using test data to obtain a test result. Figure 9 Yes Figure 1 The specific description of step 103 is based on Figure 9 The embodiment shown includes the following steps:
[0111] Step 901: Use test data in a random order as input to a first test case set.
[0112] In this embodiment, the test data for testing the first test case set are arranged in a random order and used as input of the first test case set.
[0113] For example, a test case set is used to test whether the functions of three buttons in an interface window remain independent after being pressed in different orders. The test data includes clicking the first button (click1), clicking the second button (click2), and clicking the third button (click3). Click1, click2, and click3 can be randomly arranged, and the corresponding buttons can be clicked in the arranged order for testing. For example, randomly arranging click1, click2, and click3 can obtain the sequential combination of (click1, click2, click3), (click1, click3, click2), (click2, click1, click3), (click2, click3, click1), (click3, click2, click1), and (click3, click1, click2). This sequential combination can achieve comprehensive test coverage of the test data for the first test case set.
[0114] Step 902: execute the first test case set to obtain test results.
[0115] In this embodiment, based on the input of the determined first test case set, the first test case set is executed to obtain the output corresponding to the program in the first test case set, that is, the test output.
[0116] In one implementation of this embodiment, when the function under test is the following code:
[0117] def test_func():
[0118] a=int(input())
[0119] b=int(input())
[0120] return ab
[0121] When the function under test is executed with the inputs 10, 3, the only result returned is 7. When the function under test is executed with the random order of 10, 3 set to 3, 10, the result returned is -7. This allows for greater test coverage of the object under test using the same test data.
[0122] In this embodiment, the first test case set is tested in different orders according to the data in the test data to obtain test results, thereby improving the test coverage of the object under test and helping to more comprehensively discover possible problems in the software.
[0123] The disclosed embodiment provides a software testing method, which uses a first test unit to run a first test case set of a tested object, wherein the first test case set is designed based on a second test unit and includes a specified tag, and the tested object is in at least one form of a function, method, class, or file, providing a large number of test cases for software testing; uses the first test unit to initialize test data, and the test data includes the input and output of the tested object corresponding to the second test unit, providing diverse data input for testing the above test cases; tests the first test case set with the test data to obtain test results, thus completing the test of the first test case set; verifies the test results, and uses the first test unit to generate a test report for the tested object, and calculates test indicators. This improves test efficiency and test coverage.
[0124] Corresponding to the methods provided in the above-mentioned embodiments, the present disclosure also provides a software testing device. Since the device provided in the embodiment of the present disclosure corresponds to the methods provided in the above-mentioned embodiments, the implementation method is also applicable to the device provided in this embodiment and will not be described in detail in this embodiment.
[0125] Figure 10 FIG. 1 is a structural diagram of a software testing device 1000 according to an embodiment of the present disclosure. Figure 10 As shown, the software testing device includes:
[0126] A test case running module 1010 is configured to run a first test case set of a test object using a first test unit, wherein the first test case set is designed based on the second test unit and includes a designated tag, the test object is in the form of at least one of a function, a method, a class, and a file, and the designated tag is a functional type of the test object;
[0127] A test data initialization module 1020 is configured to initialize test data using the first test unit, where the test data includes inputs and outputs of the object under test corresponding to the second test unit;
[0128] A testing module 1030 is configured to test the first test case set using the test data to obtain a test result;
[0129] The verification module 1040 is configured to verify the test result and generate a test report of the tested object using the first test unit.
[0130] In some embodiments, the testing module 1030 is used to:
[0131] In a specified test environment, test data is used as input of a first test case set, the first test case set is run, and test results are obtained. The specified test environment includes dependencies of the first test unit and the second test unit, and the dependency is at least one of the functions, modules or files that support the normal operation of the first test unit and the second test unit.
[0132] In some embodiments, before verifying the test results, the verification module 1040 is further configured to:
[0133] A preset verification rule is obtained, where the preset verification rule includes a verification function and / or assertion verification supported by the second test unit.
[0134] In some embodiments, the verification module 1040 is configured to:
[0135] Verify the test results and obtain the test output, which indicates whether the test result has passed or failed the verification;
[0136] If the test output is that the test result passes verification, the first test case, the first test data, and the first test output are recorded by the first test unit, and the test results are analyzed to generate a test report; wherein the first test case is at least one item in the first test case set, the first test data is one of the test data, and the first test result is the output obtained by executing the first test data in the first test case;
[0137] If the test output is that the test result fails verification, the first test case, the first test data and the first verification failure information are recorded in the log file, wherein the first verification failure information is the error information generated when the first test data is executed in the first test case.
[0138] In some embodiments, before using the first test unit to run the first test case set of the tested object, the test case running module 1010 is further configured to:
[0139] Add a label to the object being tested. The label is used to identify the functional type of the object being tested.
[0140] Based on the tag, a first test case set is screened out from the test case set, wherein the test case set includes the first test case set.
[0141] In some embodiments, the testing module 1030 is further configured to:
[0142] The test data is used as the input of the first test case set in random order;
[0143] Execute the first test case set and obtain the test results.
[0144] In summary, a software testing device uses a first test unit to run a first test case set for a tested object, wherein the first test case set is designed based on a second test unit and includes a specified tag, and the tested object is in the form of at least one of a function, a method, a class, and a file; the first test unit is used to initialize test data, and the test data includes the input and output of the tested object corresponding to the second test unit; the first test case set is tested using the test data to obtain test results; the test results are verified, and a test report for the tested object is generated using the first test unit. This device solves the problems of low application software testing efficiency and low test coverage, thereby improving test efficiency and test coverage.
[0145] The embodiments provided above in this disclosure describe the methods and devices provided in these embodiments. To implement the various functions in the methods provided in these embodiments, electronic devices may include hardware structures and software modules, and implement these functions in the form of hardware structures, software modules, or a combination of hardware structures and software modules. Certain of these functions may be implemented in the form of hardware structures, software modules, or a combination of hardware structures and software modules.
[0146] Figure 11 is a block diagram of an electronic device 1100 for implementing the above software testing method according to an exemplary embodiment.
[0147] For example, the electronic device 1100 may be a mobile phone, a computer, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, and the like.
[0148] Reference Figure 11 , the electronic device 1100 may include one or more of the following components: a processing component 1102 , a memory 1104 , a power component 1106 , a multimedia component 1108 , an audio component 1110 , an input / output (I / O) interface 1112 , a sensor component 1114 , and a communication component 1116 .
[0149] The processing component 1102 generally controls the overall operation of the electronic device 1100, such as operations associated with display, phone calls, data communications, camera operation, and recording operations. The processing component 1102 may include one or more processors 1120 to execute instructions to perform all or part of the steps of the above-described method. In addition, the processing component 1102 may include one or more modules to facilitate interaction between the processing component 1102 and other components. For example, the processing component 1102 may include a multimedia module to facilitate interaction between the multimedia component 1108 and the processing component 1102.
[0150] The memory 1104 is configured to store various types of data to support operations on the electronic device 600. Examples of such data include instructions for any application or method operating on the electronic device 1100, contact data, phone book data, messages, pictures, videos, etc. The memory 1104 can be implemented by any type of volatile or non-volatile storage device, or a combination thereof, 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 disk, or optical disk.
[0151] The power supply component 1106 provides power to the various components of the electronic device 1100. The power supply component 1106 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device 1100.
[0152] The multimedia component 1108 includes a screen that provides an output interface between the electronic device 1100 and the user. 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 the user. The touch panel includes one or more touch sensors to sense touches, slides, and gestures on the touch panel. The touch sensor can not only sense the boundaries of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 1108 includes a front camera and / or a rear camera. When the electronic device 1100 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera can receive external multimedia data. Each front camera and rear camera can be a fixed optical lens system or have focal length and optical zoom capabilities.
[0153] The audio component 1110 is configured to output and / or input audio signals. For example, the audio component 1110 includes a microphone (MIC), which is configured to receive external audio signals when the electronic device 1100 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signal can be further stored in the memory 1104 or transmitted via the communication component 1116. In some embodiments, the audio component 1110 also includes a speaker for outputting audio signals.
[0154] I / O interface 1112 provides an interface between processing component 1102 and peripheral interface modules, such as a keyboard, click wheel, buttons, etc. These buttons may include but are not limited to: a home button, volume buttons, a start button, and a lock button.
[0155] The sensor assembly 1114 includes one or more sensors for providing various aspects of the status assessment of the electronic device 1100. For example, the sensor assembly 1114 can detect the open / closed state of the electronic device 1100, the relative positioning of components, such as the display and keypad of the electronic device 1100. The sensor assembly 1114 can also detect changes in the position of the electronic device 1100 or a component of the electronic device 1100, the presence or absence of user contact with the electronic device 1100, the orientation or acceleration / deceleration of the electronic device 1100, and changes in the temperature of the electronic device 1100. The sensor assembly 1114 can include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 1114 can also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 1114 can also include an accelerometer, a gyroscope, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0156] The communication component 1116 is configured to facilitate wired or wireless communication between the electronic device 1100 and other devices. The electronic device 1100 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, 4G LTE, 5G NR (NewRadio) or a combination thereof. In an exemplary embodiment, the communication component 1116 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 1116 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0157] In an exemplary embodiment, the electronic device 1100 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 components to perform the above-described methods.
[0158] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 1104 including instructions, and the instructions can be executed by the processor 1120 of the electronic device 1100 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0159] The embodiments of the present disclosure further provide a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable a computer to execute the software testing method described in the above embodiments of the present disclosure.
[0160] An embodiment of the present disclosure further provides a computer program product, including a computer program, which executes the software testing method described in the above embodiment of the present disclosure when a processor is used to execute the computer program.
[0161] It should be noted that the terms "first," "second," and the like in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or precedence. It should be understood that the numbers used in this manner are interchangeable where appropriate so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of apparatus and methods consistent with certain aspects of the present disclosure as detailed in the appended claims.
[0162] Throughout this specification, reference to terms such as "one embodiment," "some embodiments," "illustrative embodiments," "examples," "specific examples," or "some examples" means that a specific feature, structure, material, or characteristic described in conjunction with an embodiment or example is included in at least one embodiment or example of the present disclosure. In this specification, the illustrative use of the above terms does not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
[0163] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present disclosure includes additional implementations in which functions may be performed out of the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by those skilled in the art to which the embodiments of the present disclosure belong.
[0164] The logic and / or steps represented in the flowcharts or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing the logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (e.g., a computer-based system, a system including a processing module, or other system that can fetch and execute instructions from an instruction execution system, apparatus, or device). For purposes of this specification, a "computer-readable medium" can be any device that can contain, store, communicate, propagate, or transport a program for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples (non-exhaustive list) of computer-readable media include the following: an electrical connection having one or more wires (control method), a portable computer disk cartridge (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and programmable read-only memory (EPROM or flash memory), fiber optic devices, and a portable compact disc read-only memory (CDROM). Furthermore, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or otherwise processing it in a suitable manner if necessary, and then storing it in a computer memory.
[0165] It should be understood that the various parts of the embodiments of the present disclosure can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented using hardware, as in another embodiment, any one of the following technologies known in the art or a combination thereof can be used to implement: a discrete logic circuit having a logic gate circuit for implementing a logic function on a data signal, an application-specific integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0166] Those skilled in the art will understand that all or part of the steps in the method of the above embodiment can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium. When the program is executed, it includes one or a combination of the steps of the method embodiment.
[0167] In addition, the functional units in the various embodiments of the present disclosure may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into a module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium. The above-mentioned storage medium may be a read-only memory, a magnetic disk, an optical disk, etc.
[0168] Although the embodiments of the present disclosure have been shown and described above, it is understood that the above embodiments are exemplary and are not to be construed as limitations on the present disclosure. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present disclosure.
Claims
1. A software testing method, characterized in that: The method comprises: Using the first test unit to run a first test case set of the object under test, wherein the first test case set is designed based on the second test unit and includes a specified tag, the object under test is in at least one form of a function, a method, a class, and a file, and the specified tag is a functional type of the object under test; Initialize test data using the first test unit, where the test data includes input and output of the object under test corresponding to the second test unit; Testing the first test case set using the test data to obtain a test result; Verify the test result and use the first test unit to generate a test report for the object under test.
2. The method according to claim 1, characterized in that The step of testing the first test case set using the test data to obtain a test result includes: In a specified test environment, the test data is used as input of the first test case set, the first test case set is run, and the test results are obtained. The specified test environment includes dependencies of the first test unit and the second test unit, and the dependencies are at least one of the functions, modules or files that support the normal operation of the first test unit and the second test unit.
3. The method according to claim 1, characterized in that Before verifying the test result, the method includes: A preset verification rule is obtained, where the preset verification rule includes a verification function and / or assertion verification supported by the second test unit.
4. The method according to claim 1, wherein The verifying the test result and generating a test report of the tested object using the first test unit includes: Verifying the test result to obtain a test output, wherein the test output indicates whether the test result passes or fails verification; If the test output is that the test result passes verification, then the first test unit records the first test case, the first test data, and the first test output and analyzes the test result to generate the test report; wherein the first test case is at least one item in the first test case set, the first test data is one of the test data, and the first test result is the output obtained by executing the first test data in the first test case; If the test output is that the test result fails verification, the first test case, the first test data and the first verification failure information are recorded in a log file, wherein the first verification failure information is the error information generated when the first test data is executed in the first test case.
5. The method according to claim 1, wherein Before using the first test unit to run the first test case set of the tested object, the method further includes: Adding a label to the object under test, wherein the label is used to identify the function type of the object under test; Based on the tag, the first test case set is filtered out from a test case set, wherein the test case set includes the first test case set.
6. The method according to claim 1, characterized in that Testing the first test case set using the test data to obtain a test result further includes: Using the test data as input of the first test case set in a random order; Execute the first test case set to obtain the test result.
7. A software testing device, characterized in that: The device comprises: A test case running module, configured to use the first test unit to run a first test case set of the object under test, wherein the first test case set is designed based on the second test unit and includes a specified tag, and the object under test is in the form of at least one of a function, a method, a class, and a file; a test data initialization module, configured to use the first test unit to initialize test data, the test data including the input and output of the object under test corresponding to the second test unit; A testing module, configured to test the first test case set using the test data to obtain a test result; A verification module is used to verify the test result and generate a test report for the object under test using the first test unit.
8. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 6.
9. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 6.
10. A computer program product, characterized in that The invention comprises a computer program which, when executed by a processor, implements the method according to any one of claims 1 to 6.