Test case processing method and device, storage medium and electronic equipment
By setting common scenarios in the test case test files and using custom tags, the problem of low orchestration flexibility in the existing technology is solved, and flexible configuration of the front and back operations of the test case is realized, improving orchestration efficiency and flexibility.
Patent Information
- Application Number
- CN202411833749.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-12
- Publication Date
- 2025-04-08
AI Technical Summary
In the prior art, when orchestrating test cases, the orchestration flexibility is low, and it is impossible to achieve flexible configuration of the pre- and post-operation of the test cases.
Flexible configuration of pre-and-post operations of test cases is achieved by setting common scenarios in the test case's test file and using custom tags to indicate execution logic.
Improve the orchestration flexibility of test cases, improve orchestration efficiency, and reduce resource waste.
Smart Images

Figure CN119782156A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present disclosure relate to the field of computer technology, and more specifically, the embodiments of the present disclosure relate to a test case processing method, a test case processing device, a computer-readable storage medium, and an electronic device. Background Art
[0002] This section is intended to provide a background or context to the embodiments of the disclosure that are recited in the claims. No description herein is admitted to be prior art by inclusion in this section.
[0003] In the related art, users can use an automated testing framework to complete the arrangement and use of test cases. For example, the Cucumber automated testing framework can be used to complete the arrangement and use of test cases. Specifically, Cucumber is a behavior-driven development (BDD) automated testing framework that can use a specific language called Gherkin to describe the behavior of an application. Since Gherkin is very close to natural language, it allows non-technical personnel to understand and participate in testing.
[0004] When Cucumber executes a test case, it parses the specified test file, scenario, and step step by step, and uses regular expressions to find the step definition corresponding to the step, that is, the underlying code logic, to run the test case. Summary of the invention
[0005] However, in many cases, when composing test cases, some common operations need to be performed before and after each scenario. Although Cucumber's own Hooks function can support these pre- and post-operations in each scenario, the Hooks operation adopts a fixed operation mechanism. In this way, when it is necessary to configure the pre- and post-operations of the test case in a new way or to customize the requirements, the solutions in the related technology cannot be implemented.
[0006] It can be seen that in the related art, when arranging test cases, there is a problem of low arrangement flexibility.
[0007] In view of this, the present disclosure provides a test case processing method, a test case processing device, a computer-readable storage medium, and an electronic device to improve the processing flexibility of test cases to a certain extent.
[0008] According to a first aspect of the present disclosure, a test case processing method is provided, the method comprising:
[0009] Obtain a test case; the test file corresponding to the test case includes a general scenario, and the general scenario is provided with a custom tag for indicating the execution logic;
[0010] The test case is tested according to the custom tag corresponding to the general scenario.
[0011] In a possible implementation, before obtaining the test case, the method further includes:
[0012] The general pre-operation logic and / or general post-operation logic corresponding to the general test scenario included in the test file are written using a language for writing general test scenarios to form the general scenario.
[0013] In a possible implementation, testing the test case according to the custom tag corresponding to the general scenario includes:
[0014] After the test file has been loaded but before being executed, obtain all common test scenarios and the general scenarios included in the test file, as well as labels corresponding to all the common test scenarios and the general scenarios;
[0015] If the tag corresponding to the general scenario is the first preset tag, it supports executing the general scenario before all the common test scenarios.
[0016] In a possible implementation, the method further includes:
[0017] If the tag corresponding to the general scenario is the second preset tag, it supports executing the general scenario after all the common test scenarios.
[0018] In a possible implementation, testing the test case according to the custom tag corresponding to the general scenario includes:
[0019] When running a scenario in the test file, obtaining all common test scenarios and the general scenario included in the test file, and labels corresponding to all common test scenarios and the general scenario respectively;
[0020] If all the common test scenarios execute the general scenario, and the tag corresponding to the general scenario is a third preset tag, then it supports executing the general scenario before executing each of the common test scenarios.
[0021] In a possible implementation, the method further includes:
[0022] If all the common test scenarios execute the general scenario, and the tag corresponding to the general scenario is the fourth preset tag, then it supports executing the general scenario after executing each of the common test scenarios.
[0023] In a possible implementation, the method further includes:
[0024] Determine a first set, the first set comprising: the common test scenario in the test file, in which the general scenario is executed only once;
[0025] If the label corresponding to the general scenario is the fifth preset label, then the label of the ordinary test scenario in the first set with a higher priority than the general scenario is specified to perform atomic changes, and only supports executing the general scenario once before the first ordinary test scene in the first set.
[0026] In a possible implementation, the method further includes:
[0027] If the label corresponding to the general scenario is the sixth preset label, then the label of the common test scenario with a lower priority than the general scenario in the first set is specified to perform atomic changes, and only supports executing the general scenario once after the last common test scenario in the first set.
[0028] In a possible implementation, the method further includes:
[0029] If an exception occurs in the general scenario, it is processed according to the processing instruction, wherein the processing instruction is an exception throwing or a jump label.
[0030] According to a second aspect of the present disclosure, a test case processing device is provided, the device comprising:
[0031] An acquisition unit, used for acquiring a test case; the test file corresponding to the test case includes a general scenario, and the general scenario is provided with a custom tag for indicating the execution logic;
[0032] The test unit is used to test the test case according to the custom tag corresponding to the general scenario.
[0033] In a possible implementation manner, before obtaining the test case, the apparatus further includes a component unit configured to:
[0034] The general pre-operation logic and / or general post-operation logic corresponding to the general test scenario included in the test file are written using a language for writing general test scenarios to form the general scenario.
[0035] In a possible implementation manner, the testing unit is used to:
[0036] After the test file has been loaded but before being executed, obtain all common test scenarios and the general scenarios included in the test file, as well as labels corresponding to all the common test scenarios and the general scenarios;
[0037] If the tag corresponding to the general scenario is the first preset tag, it supports executing the general scenario before all the common test scenarios.
[0038] In a possible implementation manner, the testing unit is used to:
[0039] If the tag corresponding to the general scenario is the second preset tag, it supports executing the general scenario after all the common test scenarios.
[0040] In a possible implementation manner, the testing unit is used to:
[0041] When running a scenario in the test file, obtaining all common test scenarios and the general scenario included in the test file, and labels corresponding to all common test scenarios and the general scenario respectively;
[0042] If all the common test scenarios execute the general scenario, and the tag corresponding to the general scenario is a third preset tag, then it supports executing the general scenario before executing each of the common test scenarios.
[0043] In a possible implementation manner, the testing unit is used to:
[0044] If all the common test scenarios execute the general scenario, and the tag corresponding to the general scenario is the fourth preset tag, then it supports executing the general scenario after executing each of the common test scenarios.
[0045] In a possible implementation manner, the testing unit is used to:
[0046] Determine a first set, the first set comprising: the common test scenario in the test file, in which the general scenario is executed only once;
[0047] If the label corresponding to the general scenario is the fifth preset label, then the label of the ordinary test scenario in the first set with a higher priority than the general scenario is specified to perform atomic changes, and only supports executing the general scenario once before the first ordinary test scene in the first set.
[0048] In a possible implementation manner, the testing unit is used to:
[0049] If the label corresponding to the general scenario is the sixth preset label, then the label of the common test scenario with a lower priority than the general scenario in the first set is specified to perform atomic changes, and only supports executing the general scenario once after the last common test scenario in the first set.
[0050] In a possible implementation manner, the device further includes a processing unit, configured to:
[0051] If an exception occurs in the general scenario, it is processed according to the processing instruction, wherein the processing instruction is an exception throwing or a jump label.
[0052] According to a third aspect of the present disclosure, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the method of the first aspect and possible implementations thereof are implemented.
[0053] According to a fourth aspect of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to execute the method of the above-mentioned first aspect and its possible implementation methods by executing the executable instructions.
[0054] The technical solution disclosed in this disclosure has the following beneficial effects:
[0055] In the disclosed embodiment, a test case can be obtained; the test file corresponding to the test case includes a general scenario, and the general scenario is provided with a custom tag for indicating the execution logic; then the test case can be tested according to the custom tag corresponding to the general scenario. It can be seen that in the disclosed embodiment, various configurations of the pre-operation logic and / or post-operation logic of the test case can be implemented by adjusting the custom tag for indicating the execution logic set in the general scenario, thereby improving the flexibility of the test case arrangement, thereby improving the test case arrangement efficiency, and reducing the waste of resources when executing the test case arrangement.
[0056] Other features and advantages of the present disclosure will be described in the following description, and partly become apparent from the description, or be understood by practicing the present disclosure. The purpose and other advantages of the present disclosure can be realized and obtained by the structures particularly pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings required for use in the embodiments of the present disclosure will be briefly introduced below. Obviously, the drawings introduced below are only some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0058] Figure 1 A schematic diagram of an application scenario in this exemplary embodiment is shown;
[0059] Figure 2 A flowchart showing a test case processing method in this exemplary embodiment;
[0060] Figure 3 A schematic diagram showing a custom tag corresponding to a common scenario in this exemplary embodiment;
[0061] Figure 4 A schematic diagram showing the structure of a test case processing device in this exemplary embodiment is shown;
[0062] Figure 5 A schematic structural diagram of an electronic device in this exemplary embodiment is shown. DETAILED DESCRIPTION
[0063] In order to make the purpose, technical solutions and advantages of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present disclosure. In the absence of conflict, the embodiments in the present disclosure and the features in the embodiments can be arbitrarily combined with each other. In addition, although the logical order is shown in the flow chart, in some cases, the steps shown or described can be performed in an order different from that here.
[0064] The term "comprising" and any variations thereof in the specification and claims of the present disclosure are intended to cover non-exclusive protection. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products or devices.
[0065] In the embodiments of the present disclosure, one or more, "many" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can represent: a, b, c, ab, ac, bc, or abc, where a, b, c can be single or plural.
[0066] It should be noted that the terms "first", "second", etc. 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, sequence, size, and priority. For example, the first preset label and the second preset label in the embodiment of the present disclosure are only used to distinguish different preset labels. It should be understood that the data used in this way can be 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 devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0067] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, which are schematic diagrams of the present disclosure and are not necessarily drawn to scale. Some of the block diagrams shown in the accompanying drawings may be functional entities, which do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or in hardware modules or integrated circuits, or in networks, processors or microcontrollers. The implementation can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein. The features, structures or characteristics described in the present disclosure may be combined in one or more implementations in any suitable manner. In the following description, many specific details are provided to provide a full description of the implementation of the present disclosure. However, those skilled in the art should be aware that one or more specific details may be omitted when implementing the technical solution of the present disclosure, or one or more specific details may be replaced by other methods, components, devices, steps, etc. It should be noted that in the embodiments of the present disclosure, the dissemination and use of data (such as test cases) are in compliance with relevant national laws and regulations. SUMMARY OF THE INVENTION
[0069] In the related art, users can use an automated testing framework to complete the arrangement and use of test cases. For example, the Cucumber automated testing framework can be used to complete the arrangement and use of test cases.
[0070] When Cucumber executes a test case, it will parse the specified .Feature file, scenario, and step step by step, and find the underlying code logic (step definition) corresponding to the step through regular expressions to run the test case. In many cases, when composing test cases, it is necessary to perform certain common operations before and after each scenario, for example, the common operation of initializing data before the scenario is executed and the common operation of cleaning up the environment after the scenario is executed.
[0071] Although Cucumber's own Hooks function can support these pre- and post-operations in each Scenario, Hooks are executed using a fixed mechanism. For example, if the pre-operation fails, the test case will not be able to continue to execute; if the post-operation fails, the test case will still continue to execute.
[0072] However, in actual testing, if the scenario requires flexible configuration, such as whether to continue running or terminate after Hooks fails, or even support some customized operations such as printing logs, retrying, jumping, etc., it cannot be achieved in the related technology. In other words, in the related technology, when arranging test cases, there is a problem of low arrangement flexibility.
[0073] In view of this, the present disclosure provides a test case processing method, through which a test case can be obtained; the test file corresponding to the test case includes a general scenario, and the general scenario is provided with a custom tag for indicating the execution logic; then the test case can be tested according to the custom tag corresponding to the general scenario. It can be seen that in the embodiment of the present disclosure, various configurations of the pre-operation logic and / or post-operation logic of the test case can be implemented by adjusting the custom tag for indicating the execution logic set in the general scenario, thereby improving the flexibility of the test case arrangement, and then improving the test case arrangement efficiency, and reducing the waste of resources when executing the test case arrangement.
[0074] After introducing the basic principles of the present disclosure, various non-limiting embodiments of the present disclosure are described in detail below.
[0075] Application Scenario Overview
[0076] In order to better understand the technical solutions provided by the embodiments of the present disclosure, the following briefly introduces the application scenarios to which the technical solutions provided by the embodiments of the present disclosure are applicable. It should be noted that the application scenarios introduced below are only used to illustrate the embodiments of the present disclosure and are not intended to limit the present disclosure. In specific implementation, the technical solutions provided by the embodiments of the present disclosure can be flexibly applied according to actual needs.
[0077] In order to more clearly introduce the contents of the embodiments of the present disclosure, some key terms are introduced below:
[0078] 1. Cucumber: A behavior-driven development (BDD) automated testing framework that uses a specific language called Gherkin to describe the behavior of an application. Since Gherkin is very close to natural language, the test cases corresponding to the behavior of the application described by Gherkin allow users to describe the operations performed by the software system in a way that does not require attention to specific implementation details, so that non-technical personnel can also understand the corresponding test cases and participate in the tests performed based on the test cases.
[0079] 2. Feature file: It is a file format in Cucumber. Feature files are written in Gherkin language. Feature files are used to describe test scenarios and test steps. Feature files consist of the following parts:
[0080] (1) Feature: It is used to describe the test requirements, usually describing a function or characteristic of the system being tested.
[0081] (2) Scenario: used to describe a specific test scenario or use case. Each feature consists of a set of scenarios, so a .Feature file usually contains multiple scenarios.
[0082] (3) Step: Describes the specific steps in the test scenario. It is the smallest test unit and includes keywords such as Given, When, and Then. There are usually multiple steps in a scenario.
[0083] (4) Tag: You can define a tag name for each scenario. Using tags helps organize or group all test scenarios in a feature file, and use tags to run specified scenarios during testing.
[0084] In the embodiments of the present disclosure, the test case processing technology can be applied to business scenarios for testing various business platforms that need to be tested, such as music platforms, video playback platforms, product sales platforms, dating platforms and other business platforms. For example, the business scenario of testing a music platform is not limited to this in the embodiments of the present disclosure.
[0085] See also Figure 1 As shown, Figure 1 This is an application scenario to which the technical solution of the embodiment of the present disclosure can be applied. In the scenario diagram, a terminal device 101 and an electronic device 102 are included. The terminal device 101 can be multiple devices. Figure 1 Only one is shown, that is, multiple users can participate in corresponding tests based on corresponding terminal devices 101 respectively, and the electronic device 102 can execute the processing of requests for testing the service platform triggered by multiple terminal devices 101.
[0086] The terminal device 101 and the electronic device 102 , as well as each terminal device 101 , may be directly or indirectly connected to each other through one or more networks 103 .
[0087] In the embodiment of the present disclosure, a user can log in to the terminal device 101 and send a test request to the electronic device 102. Then the electronic device 102 can obtain the test case. The test file corresponding to the test case includes a general scenario. The general scenario is provided with a custom tag for indicating the execution logic. Then, the test case can be tested according to the custom tag corresponding to the general scenario, and the obtained test results can be sent to the terminal device 101.
[0088] in, Figure 1 The terminal device 101 may be a mobile phone, a tablet computer (PAD), a personal computer (PC), a smart TV, a smart watch, a smart speaker, a smart car device, and a wearable device, but is not limited thereto. These devices may have the function of supporting participation in the target task.
[0089] as well as, Figure 1 The electronic device 102 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It may also be a cloud server or a cloud server cluster that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms, but is not limited to these.
[0090] Of course, the method provided in the embodiment of the present disclosure is not limited to Figure 1 The application scenario shown can also be used in other possible application scenarios, such as an application scenario where the test case processing method is implemented only by an electronic device, and the embodiments of the present disclosure are not limited thereto.
[0091] Exemplary Methods
[0092] To further illustrate the technical solution provided by the embodiments of the present disclosure, this is described in detail below in conjunction with the accompanying drawings and specific implementation methods. Although the embodiments of the present disclosure provide method operation steps as shown in the following embodiments or drawings, more or fewer operation steps may be included in the method based on routine or no creative labor. In the steps where there is no necessary causal relationship logically, the execution order of these steps is not limited to the execution order provided by the embodiments of the present disclosure. The method may be executed in the order of the method shown in the embodiments or drawings or in parallel during the actual processing process or when the device is executed.
[0093] See also Figure 2 , Figure 2 1 is a flow chart of a test case processing method in an embodiment of the present disclosure. The Cucumber test framework will be used as an example for illustration below. It should be understood that this embodiment can also be applied to other test frameworks. The flow of the method can be, for example, performed by an electronic device, such as Figure 1 The electronic device 102 in the embodiment is executed, and the specific implementation process of the method is as follows:
[0094] Step 201: Acquire a test case; the test file corresponding to the test case includes a general scenario, and the general scenario is provided with a custom tag for indicating the execution logic.
[0095] In an embodiment of the present disclosure, before the electronic device obtains a test case, the electronic device may also use a language for writing common test scenarios, such as the Gherkin language, to write common pre-operation logic and / or common post-operation logic corresponding to the common test scenarios included in the test file to form a common scenario.
[0096] It can be seen that in the embodiments of the present disclosure, in order to ensure that the use case text (such as Feature files) is clear and unambiguous, in other words, in order to enable non-technical personnel (such as front-end R&D personnel, etc.) to view and understand the test workflow by only reading Feature files, the general pre-operation logic and / or post-operation logic can no longer be hidden in the initial entry class, that is, the pre-operation logic and / or post-operation logic are not implemented in the form of annotations and codes, but are consistent with ordinary use case scenarios, such as using the Gherkin language to describe the general scenarios corresponding to the pre-operation logic and / or post-operation logic that constitute the steps in the Feature file. In this way, the readability of the test case text can be improved, thereby improving the user experience.
[0097] It should be noted that, for the sake of ease of description, the following text describes the common scenarios corresponding to the pre-operation logic and / or post-operation logic as common scenarios. Obviously, the common scenarios include the scenarios corresponding to the pre-logic described in the Gherkin language, or the common scenarios include the scenarios corresponding to the post-logic described in the Gherkin language, or the common scenarios include the scenarios corresponding to the pre-logic and the post-logic described in the Gherkin language.
[0098] Step 202: Test the test case according to the custom tags corresponding to the general scenario.
[0099] In the embodiment of the present disclosure, when the electronic device runs the Cucumber test case, it can, but is not limited to, execute the following process steps: Step A: Initialize the driver entry class; Step B: Load Feature file metadata; Step C: Run the Feature file.
[0100] In a possible implementation, after step A, that is, before initializing and loading the Feature file, a custom operation can be inserted into the driver entry class as the most advanced initialization operation before all Feature files are executed.
[0101] In a possible implementation, if the electronic device is after step B, that is, after the test file has been loaded but before execution, the electronic device can obtain all common test scenarios and general scenarios included in the test file, as well as the labels corresponding to all common test scenarios and general scenarios. In other words, the electronic device can obtain all the scenes in the Feature file (that is, the aforementioned test file) and their annotated Tag labels, specifically including the preceding and following scenes (that is, the aforementioned general scenes) and their labels, and the common test scenes and their labels.
[0102] Optionally, if the tag corresponding to the general scenario is the first preset tag, it supports executing the general scenario before all common test scenarios. The first preset tag is, for example, Tag A1, which is used to indicate that its priority is higher than the priority of the tags corresponding to all common scenarios, that is, it supports executing the general scenario marked with A1 before all use cases of the Feature file.
[0103] Optionally, if the tag corresponding to the general scenario is the second preset tag, it supports executing the general scenario after all common test scenarios. The second preset tag is, for example, Tag A2, which is used to indicate that its priority is lower than the priority of the tags corresponding to all common scenarios, that is, it supports executing the general scenario marked with A2 after all use cases of the Feature file.
[0104] In a possible implementation, when running a scenario in a test file, all common test scenarios and general scenarios included in the test file, as well as the tags corresponding to all common test scenarios and general scenarios, are obtained. Specifically, when running a Scenario in a Feature file, the file is read line by line in text order, and the tags at the first line of the Scenario are first obtained, including the tags of the general scenarios and the tags of the common test scenarios.
[0105] Optionally, in the Tag context, if all common test scenarios execute the general scenario, and the tag corresponding to the general scenario is the third preset tag, it supports executing the general scenario before executing each common test scenario. The third preset tag is, for example, Tag B1, and Tag B1 is used to indicate that its priority is higher than the priority of the tags corresponding to other common test scenarios marked on the Scenario. In other words, it supports executing the general scenario marked with B1 before each common test scenario.
[0106] Optionally, in the Tag context, if all common test scenarios execute the general scenario, and the tag corresponding to the general scenario is the fourth preset tag, then it is supported to execute the general scenario after executing each common test scenario. The fourth preset tag is, for example, Tag B2, and Tag B2 is used to indicate that its priority is lower than the priority of the tags corresponding to other common test scenarios marked on the Scenario. In other words, it is supported to execute the general scenario marked with B2 after each common test scenario.
[0107] In a possible implementation, the electronic device may also determine a first set, where the first set includes: in the test file, common test scenarios in which general scenarios are executed only once.
[0108] Optionally, if the tag corresponding to the general scenario is the fifth preset tag, then the tags in the first set that have a higher priority than the ordinary test scenarios on the general scenario are specified to perform atomic changes, and only support the execution of the general scenario once before the first ordinary test scenario in the first set. Among them, the atomic change can be understood as a unique change, that is, the processing is only performed once for all tags marked with ordinary test scenarios. The fifth preset tag is, for example, Tag C1. Tag C1 is used to indicate that its priority is higher than the priority of the tags corresponding to other ordinary test scenarios marked on the Scenario and to make atomic changes. In other words, it only supports the execution of the general scenario marked with C1 once before the first ordinary test scene.
[0109] Optionally, if the tag corresponding to the general scenario is the sixth preset tag, then the tags of the general test scenarios in the first set whose priority is lower than that of the general scenario are specified to perform atomic changes, and only support the execution of the general scenario once after the last general test scenario in the first set. Among them, the atomic change can be understood as a unique change, that is, the processing is only performed once for all tags marked with general test scenarios. The sixth preset tag is, for example, Tag C2. Tag C2 is used to indicate that its priority is lower than the priority of the tags corresponding to other general test scenarios marked on the Scenario, and to make atomic changes. In other words, it only supports the execution of the general scenario marked with C2 once after the last general test scene.
[0110] In a possible implementation, if an exception occurs in a general scenario, it is processed according to a processing instruction, where the processing instruction is an exception throw or a jump label.
[0111] For example, the exceptions that fail when running the general scenarios marked with A1 and A2 are captured and processed as required. For example, the test execution can be terminated by throwing an exception, and the execution of other use cases can be transferred to the tag by jumping.
[0112] For example, the exceptions that fail when running the general scenarios marked with B1 and B2 are captured and processed as required. For example, the test execution can be terminated by throwing an exception, and the execution of other use cases can be transferred to the tag by jumping.
[0113] For example, the exceptions that fail when running the general scenarios marked with C1 and C2 are captured and processed as required. For example, the test execution can be terminated by throwing an exception, and the execution of other use cases can be transferred to the tag by jumping.
[0114] In one possible implementation, see Figure 3As shown, in the embodiment of the present disclosure, custom tags can also be inserted in the processes of driving entry classes, Feature file loading, and Feature file running. Among them, the general scenario of A1 marking is executed before all use cases in the entire Feature file, the general scenario of A2 marking is executed after all use cases in the entire Feature file, the general scenario of B1 marking is executed before the first scene in all ordinary test scenes in the entire Feature file, the general scenario of B2 marking is executed before the last scene in all ordinary test scenes in the entire Feature file, the general scenario of C1 marking is executed before all ordinary test scenes in the entire Feature file, and the general scenario of C2 marking is executed after all ordinary test scenes in the entire Feature file.
[0115] Obviously, in the disclosed embodiment, custom tags can be inserted and interpreted in various process steps of running Cucumber test cases, such as in the process of driving entry class, feature file loading, and feature file running, so as to realize flexible combination of common test cases and pre-test cases and / or post-test cases through different insertion points of custom tags. In addition, different running strategies of subsequent test cases can be realized through the running interpretation of custom tags to meet different running requirements.
[0116] It can be seen that the embodiments of the present disclosure provide a more flexible use case arrangement method, and because the Gherkin language is used to describe the pre-operation logic and / or post-operation logic, it also solves the problem of poor experience of non-developers in reading and using test cases due to the poor readability of Feature files, thereby improving the user experience and further improving the maintainability and reusability of test cases.
[0117] Exemplary Devices
[0118] The exemplary embodiment of the present disclosure also provides a test case processing device. Figure 4 As shown, the test case processing device 400 includes the following program modules:
[0119] The acquisition unit 401 is used to acquire a test case; the test file corresponding to the test case includes a general scenario, and the general scenario is provided with a custom tag for indicating the execution logic;
[0120] The testing unit 402 is used to test the test case according to the custom tag corresponding to the general scenario.
[0121] In a possible implementation manner, before obtaining the test case, the apparatus further includes a component unit configured to:
[0122] The general pre-operation logic and / or general post-operation logic corresponding to the general test scenario included in the test file are written using a language for writing general test scenarios to form the general scenario.
[0123] In a possible implementation, the testing unit 402 is used to:
[0124] After the test file has been loaded but before being executed, obtain all common test scenarios and the general scenarios included in the test file, as well as labels corresponding to all the common test scenarios and the general scenarios;
[0125] If the tag corresponding to the general scenario is the first preset tag, it supports executing the general scenario before all the common test scenarios.
[0126] In a possible implementation, the testing unit 402 is used to:
[0127] If the tag corresponding to the general scenario is the second preset tag, it supports executing the general scenario after all the common test scenarios.
[0128] In a possible implementation, the testing unit 402 is used to:
[0129] When running a scenario in the test file, obtaining all common test scenarios and the general scenario included in the test file, and labels corresponding to all common test scenarios and the general scenario respectively;
[0130] If all the common test scenarios execute the general scenario, and the tag corresponding to the general scenario is a third preset tag, then it supports executing the general scenario before executing each of the common test scenarios.
[0131] In a possible implementation, the testing unit 402 is used to:
[0132] If all the common test scenarios execute the general scenario, and the tag corresponding to the general scenario is the fourth preset tag, then it supports executing the general scenario after executing each of the common test scenarios.
[0133] In a possible implementation, the testing unit 402 is used to:
[0134] Determine a first set, the first set comprising: the common test scenario in the test file, in which the general scenario is executed only once;
[0135] If the label corresponding to the general scenario is the fifth preset label, then the label of the ordinary test scenario in the first set with a higher priority than the general scenario is specified to perform atomic changes, and only supports executing the general scenario once before the first ordinary test scene in the first set.
[0136] In a possible implementation, the testing unit 402 is used to:
[0137] If the label corresponding to the general scenario is the sixth preset label, then the label of the common test scenario with a lower priority than the general scenario in the first set is specified to perform atomic changes, and only supports executing the general scenario once after the last common test scenario in the first set.
[0138] In a possible implementation manner, the device further includes a processing unit, configured to:
[0139] If an exception occurs in the general scenario, it is processed according to the processing instruction, wherein the processing instruction is an exception throwing or a jump label.
[0140] The specific details of each part of the above-mentioned device have been described in detail in the implementation method of the method part. The undisclosed details can be found in the implementation method of the method part, so they will not be repeated here.
[0141] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the exemplary embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.
[0142] Exemplary Program Products
[0143] The exemplary embodiments of the present disclosure also provide a computer program product, which includes a computer program, and when the computer program is executed by a processor, the test case processing method described above is implemented.
[0144] In one embodiment, the computer program product may be a tangible product containing a computer program, such as a computer-readable storage medium storing a computer program. The readable storage medium may be a storage medium based on electrical, magnetic, optical, electromagnetic, infrared, or other signals, including but not limited to: random access memory (RAM), read-only memory (ROM), magnetic tape, floppy disk, flash memory (Flash), mechanical hard disk (HDD), solid-state drive (SSD), and the like. Exemplarily, the computer program product may be implemented as a non-volatile storage medium storing a computer program, such as a read-only memory, a NAND flash memory, and the like.
[0145] In one embodiment, the computer program product may be an intangible product including a computer program. Exemplarily, the computer program product may be implemented as a virtual digital product, such as a digital file storing an executable file, an installation package, etc. of the computer program.
[0146] The code of the computer program can be written in one or more programming languages. Programming languages such as C language, Java, C++, etc. The program code can be executed entirely on the user computing device, or partially on the user computing device, or as a separate software package, or partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, such as a local area network (LAN), a wide area network (WAN), etc., or can be connected to an external computing device (e.g., an Internet connection provided by an operator).
[0147] The computer program may be carried or transmitted via electrical, magnetic, optical, electromagnetic, infrared, or other signals. The electronic device may convert the signal carrying the computer program into a digital signal, thereby running the computer program. When the computer program runs on an electronic device, its code is used to enable the electronic device to execute (more specifically, enable the processor of the electronic device to execute) the method steps of various exemplary embodiments of the present disclosure, such as the above-mentioned test case processing method, which includes the following steps:
[0148] Step 201: Get a test case; the test file corresponding to the test case includes a general scenario, and the general scenario is provided with a custom tag for indicating the execution logic; Step 202: Test the test case according to the custom tag corresponding to the general scenario.
[0149] By implementing the above method steps through a computer program, a test case can be obtained; the test file corresponding to the test case includes a general scenario, and the general scenario is provided with a custom tag for indicating the execution logic; then the test case can be tested according to the custom tag corresponding to the general scenario. It can be seen that in the embodiment of the present disclosure, various configurations of the pre-operation logic and / or post-operation logic of the test case can be implemented by adjusting the custom tag for indicating the execution logic set in the general scenario, thereby improving the flexibility of the test case arrangement, thereby improving the efficiency of the test case arrangement, and reducing the waste of resources when executing the test case arrangement.
[0150] Exemplary Electronic Devices
[0151] The exemplary embodiments of the present disclosure also provide an electronic device. The electronic device may include a processor and a memory. The memory stores executable instructions of the processor, such as a computer program. The processor executes the method steps of various exemplary embodiments of the present disclosure by executing the executable instructions.
[0152] Reference below Figure 5 , the electronic device is exemplarily described in the form of a general-purpose computing device. It should be understood that Figure 5 The electronic device 500 shown is merely an example and should not limit the functions and scope of use of the embodiments of the present disclosure.
[0153] like Figure 5 As shown, the electronic device 500 may include: a processor 510 , a memory 520 , a bus 530 , an I / O (input / output) interface 540 , a network adapter 550 , and a display 580 .
[0154] The memory 520 may include a volatile memory, such as a RAM 521, a cache unit 522, and may also include a non-volatile memory, such as a ROM 523. The memory 520 may also include one or more program modules 524, such program modules 524 include but are not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or a combination thereof may include the implementation of a network environment. For example, the program module 524 may include each module in the above-mentioned device.
[0155] The processor 510 may include one or more processing units. For example, the processor 510 may include an AP (Application Processor), a modem processor, a GPU (Graphics Processing Unit), an ISP (Image Signal Processor), a controller, an encoder, a decoder, a DSP (Digital Signal Processor), a baseband processor and / or an NPU (Neural-Network Processing Unit), etc.
[0156] The processor 510 may be used to execute the executable instructions stored in the memory 520, such as executing the above-mentioned test case processing method, which includes the following steps:
[0157] Step 201: Get a test case; the test file corresponding to the test case includes a general scenario, and the general scenario is provided with a custom tag for indicating the execution logic; Step 202: Test the test case according to the custom tag corresponding to the general scenario.
[0158] By executing the above method steps through the processor 510, a test case can be obtained; the test file corresponding to the test case includes a general scenario, and the general scenario is provided with a custom tag for indicating the execution logic; then the test case can be tested according to the custom tag corresponding to the general scenario. It can be seen that in the embodiment of the present disclosure, various configurations of the pre-operation logic and / or post-operation logic of the test case can be implemented by adjusting the custom tag for indicating the execution logic set in the general scenario, thereby improving the flexibility of the test case arrangement, and then improving the test case arrangement efficiency, and reducing the waste of resources when executing the test case arrangement.
[0159] The bus 530 is used to realize the connection between different components of the electronic device 500, and may include a data bus, an address bus, and a control bus.
[0160] The electronic device 500 can communicate with one or more external devices 600 (eg, a keyboard, a mouse, an external controller, etc.) through the I / O interface 540 .
[0161] The electronic device 500 can communicate with one or more networks through the network adapter 550. For example, the network adapter 550 can provide mobile communication solutions such as 3G / 4G / 5G, or provide wireless communication solutions such as wireless LAN, Bluetooth, near field communication, etc. The network adapter 550 can communicate with other modules of the electronic device 500 through the bus 530.
[0162] The electronic device 500 can display the test case execution status, etc. through the display 580.
[0163] although Figure 5 Not shown, other hardware and / or software modules may also be provided in the electronic device 500, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0164] As can be seen from the above, the technical solution of the present disclosure can be implemented as a method, an apparatus, a system, a computer program product, a storage medium, an electronic device, etc. Those skilled in the art can understand that various aspects of the present disclosure can be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or an implementation combining hardware and software, such as being respectively referred to as a "circuit", "module" or "system".
[0165] It should be understood that the present disclosure is not limited to the specific method steps or structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from the scope thereof. Those skilled in the art will easily think of other embodiments based on the specific embodiments provided by the present disclosure. Therefore, the specific embodiments provided by the present disclosure are only exemplary, and the scope and spirit of the present disclosure are indicated by the claims, and any variations, uses or adaptive changes of the present disclosure should be covered, which follow the general principles of the present disclosure and include common knowledge or customary technical means in the technical field that are not disclosed in the present disclosure.
Claims
1. A test case processing method, characterized in that: The method comprises: Obtain a test case; the test file corresponding to the test case includes a general scenario, and the general scenario is provided with a custom tag for indicating the execution logic; The test case is tested according to the custom tag corresponding to the general scenario.
2. The method according to claim 1, characterized in that Before obtaining the test case, the method further includes: The general pre-operation logic and / or general post-operation logic corresponding to the general test scenario included in the test file are written using a language for writing general test scenarios to form the general scenario.
3. The method according to claim 1 or 2, characterized in that: Testing the test case according to the custom tag corresponding to the general scenario includes: After the test file has been loaded but before being executed, obtain all common test scenarios and the general scenarios included in the test file, as well as labels corresponding to all the common test scenarios and the general scenarios; If the tag corresponding to the general scenario is the first preset tag, it supports executing the general scenario before all the common test scenarios.
4. The method according to claim 3, characterized in that The method further comprises: If the tag corresponding to the general scenario is the second preset tag, it supports executing the general scenario after all the common test scenarios.
5. The method according to claim 1 or 2, characterized in that: Testing the test case according to the custom tag corresponding to the general scenario includes: When running a scenario in the test file, obtaining all common test scenarios and the general scenario included in the test file, and labels corresponding to all common test scenarios and the general scenario respectively; If all the common test scenarios execute the general scenario, and the tag corresponding to the general scenario is a third preset tag, then it supports executing the general scenario before executing each of the common test scenarios.
6. The method according to claim 5, characterized in that The method further comprises: If all the common test scenarios execute the general scenario, and the tag corresponding to the general scenario is the fourth preset tag, then it supports executing the general scenario after executing each of the common test scenarios.
7. The method according to claim 6, characterized in that The method further comprises: Determine a first set, the first set comprising: the common test scenario in the test file, in which the general scenario is executed only once; If the label corresponding to the general scenario is the fifth preset label, then the label of the ordinary test scenario in the first set with a higher priority than the general scenario is specified to perform atomic changes, and only supports executing the general scenario once before the first ordinary test scene in the first set.
8. A test case processing device, characterized in that: The device comprises: An acquisition unit, used for acquiring a test case; the test file corresponding to the test case includes a general scenario, and the general scenario is provided with a custom tag for indicating the execution logic; The test unit is used to test the test case according to the custom tag corresponding to the general scenario.
9. An electronic device, characterized in that: include: processor; A memory, configured to store executable instructions of the processor; The processor is configured to perform the method of any one of claims 1 to 7 by executing the executable instructions.
10. A computer program product having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.