Method and system for testing functions of Java Swing application program
By creating and modifying placeholder tags, the problem that failed components in Java Swing applications cannot set tags is solved, and the full scene coverage and accuracy improvement of the test is achieved.
Patent Information
- Application Number
- CN202411683836.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-22
- Publication Date
- 2025-03-21
AI Technical Summary
It is difficult to identify and test custom components in Java Swing applications, especially those that rewrite the paint() method, which leads to the inability to recognize the test tool and the failed identification of the components cannot accurately set the label, affecting the test accuracy.
By creating a placeholder tag and generating an ID, you can obtain the interface for the failed identification, mark the failed component, and modify the placeholder tag to be a recognizable tag based on the marked component until it can be successfully identified.
It realizes accurate label settings for failed components in Java Swing applications, improves test accuracy and ensures full-scene coverage of tests.
Smart Images

Figure CN119669052A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of software testing, and in particular to a testing method and system for Java Swing application program functions. Background Art
[0002] Java Swing technology is a common desktop application development technology, which is based on Java. However, the Junit (unit testing framework for Java language) test for Java mainly focuses on testing interfaces and methods, which is not suitable for Java Swing. Java Swing needs a testing framework that can test interfaces and functions.
[0003] At present, the common functional testing methods for applications and web interfaces are mainly to identify the properties and names of components, establish corresponding resource pools and object libraries, and perform functional testing. Most of these tests are black box or gray box tests. Figure 1 As shown in the figure, the complete test process is briefly described as follows:
[0004] 1. Create test cases by recording operations. During the recording process, record the components and operations that can be recognized, skip the components and operations that cannot be recognized, or replace them with other operations;
[0005] 2. After recording is completed, add assertion operations (i.e. verification rules) in the graphical interface and store them;
[0006] 3. After running the test case and testing, output the test results.
[0007] The above test method has the following defects:
[0008] (1) Java Swing applications often have custom components that override the paint() method. The types of such components are usually not conventional. Most test tools cannot recognize such repainted components. Some tools use images for recognition, which is not stable and can easily lead to test case failures.
[0009] (2) Some components may have missing properties and names. Most testing tools lack the means to deal with this situation, resulting in such components being identified only by the class path or not being identified at all. When such components are in anonymous inner classes, the components need to be re-adapted as long as the code is slightly modified, otherwise the test case will fail to run. Summary of the invention
[0010] In view of the defects existing in the prior art, the technical problem solved by the present invention is: when testing the functions of a Java Swing application program, how to accurately set labels for components that fail to be identified, thereby improving the test accuracy.
[0011] To achieve the above objectives, in a first aspect, an embodiment of the present application provides a method for testing Java Swing application functions, characterized in that the method comprises the following steps:
[0012] Flow where component operation identification fails and is converted to a tag:
[0013] Create a placeholder tag and generate an ID;
[0014] Obtain an interface where recognition fails, and mark the component where recognition fails in the interface;
[0015] Change the placeholder label to a recognizable label based on the component marked in the interface when recognition fails.
[0016] In combination with the first aspect, in one implementation, the process of modifying the placeholder label to a recognizable label according to the component marked in the interface when the recognition fails includes:
[0017] The placeholder tag is located according to the interface where the recognition fails, the component-type tag corresponding to the placeholder tag is determined, and the placeholder tag is replaced with the component-type tag; and properties are set for the component-type tag according to the component marked in the interface when the recognition fails until successful recognition is achieved.
[0018] In combination with the first aspect, in one embodiment, the process of modifying the placeholder tag to a recognizable tag based on the component marked in the interface when the recognition fails includes: locating the placeholder tag according to the interface where the recognition fails, replacing the placeholder tag with a custom operation tag, setting the ID and attributes of the custom operation tag, searching for the corresponding test class according to the ID of the custom operation tag, and executing the test operation through Java code.
[0019] In combination with the first aspect, in one implementation, the method further includes the following steps:
[0020] The process of component operation recognition success and conversion into tags:
[0021] Determine the top-level container of the current component: If the top-level container is a regular top-level container, record the name attribute of the top-level container and generate the top-level container ID, then create and cache the tag class corresponding to the current top-level container; if the top-level container is a component-type container, retrieve the tag class of the top-level container from the cache;
[0022] Get the key attributes of the current component, including the name of the current component, text, text floating prompt box textToolTip and interface layout;
[0023] Determine the label of the current component according to its position in the top-level container, and set the label's PID to the top-level container ID; if the current component is a container-type component, cache the label of the current component;
[0024] Sets the action property of the current component's label.
[0025] In combination with the first aspect, in one implementation, the process of obtaining key attributes of the current component includes:
[0026] According to the query order, if any key attribute is found, it is determined that the key attribute of the current component has been obtained; the query order is:
[0027] Query the name attribute, text attribute, and textToolTip attribute in turn, and finally parse the interface layout. If the direct parent container of the current component is a FormLayout layout and there is text next to the component, obtain the text information.
[0028] In combination with the first aspect, in one implementation, the process of determining the label of the current component according to the position of the current component in the top-level container includes:
[0029] Determine the set of components in the top-level container that have the same key attributes as the current component, create a label for the current component and automatically generate an ID for the current component based on the order of the current component in the set of components;
[0030] The process of setting the operation attribute of the label of the current component includes:
[0031] For components that support multiple clicks, the action property value is set to the number of mouse clicks;
[0032] For a component that has multiple response events, the OperType attribute of the tag of the current component is determined as the operation attribute by parsing the operation performed on the current component.
[0033] In combination with the first aspect, in one implementation, the method further includes the following steps: adding custom assertion information;
[0034] Custom assertion information includes:
[0035] Assertion flag tag, used to indicate that an assertion operation is to be performed;
[0036] The result comparison tag is used to compare the actual value of the component obtained according to the component ID with the set expected value to obtain the assertion result;
[0037] Custom assertion tags are used to implement assertion operations through code.
[0038] In conjunction with the first aspect, in one implementation, the method further includes the following steps: creating a tag library;
[0039] The tag library includes a tag information library and a tag response event library;
[0040] The tag information library includes tag classes and tag attributes;
[0041] The tag class includes: the base class of tag objects, the tag base class corresponding to the Java Swing component, the JavaSwing basic component tag and the functional tag;
[0042] Functional tags include: test class tags, test case tags, public method tags, automatic attribute tags, reference public method tags, assertion tags, expected value and actual value comparison tags, and custom operation tags;
[0043] Tag attributes include basic attributes, search attributes, and operation attributes;
[0044] The tag response event library includes a tag response event corresponding to each tag in the tag information library.
[0045] In a second aspect, an embodiment of the present application provides a testing system for Java Swing application functions, the system comprising a component identification processing module, which is used to: execute the process of component operation identification failure and conversion into a label mentioned in the first aspect.
[0046] In conjunction with the second aspect, in one implementation, the system further includes:
[0047] A tag library creation module, which is used to: create the tag library mentioned in the first aspect;
[0048] A test case creation module is used to: create test cases according to tag information in the tag library;
[0049] The test case writing module is used to: write the created test cases by recording;
[0050] The test case writing module includes the component identification processing module and the assertion module:
[0051] The component identification processing module is also used to: execute the process of successfully identifying the component operation mentioned in the first aspect and converting it into a label;
[0052] The assertion module is used to: add the custom assertion information mentioned in the first aspect;
[0053] The test case execution module is used to execute the test cases written by the test case writing module and obtain the test results.
[0054] Compared with the prior art, the advantages of the present invention are:
[0055] (1) The present invention can support modifying labels in a graphical interface or using automatic labels to call test codes for use case writing by creating and modifying placeholder labels, thereby being able to comprehensively and accurately set labels for components that fail to be identified, thereby achieving full-scenario coverage of the test.
[0056] (2) The present invention provides a variety of assertion implementation methods and also supports custom assertions, thereby achieving no-dead-angle assertions for the program and being able to cope with more and more complex scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0058] Figure 1 Schematic diagram of the process and execution flow for writing functional test cases in the prior art;
[0059] Figure 2 This is a flow chart of S3 in the embodiment of the present application;
[0060] Figure 3 This is a flow chart of S4 in the embodiment of the present application;
[0061] Figure 4 This is a flow chart of S5 in the embodiment of the present application;
[0062] Figure 5 This is a schematic diagram of the hardware structure of a test device for Java Swing application functions involved in the embodiment of the present application. DETAILED DESCRIPTION
[0063] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0064] The flowcharts shown in the accompanying drawings are only examples and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may also be decomposed, combined or partially merged, so the actual execution order may change according to actual conditions.
[0065] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0066] In a first aspect, an embodiment of the present application provides a method for testing a Java Swing application function, the method comprising the following steps:
[0067] S1: Create a tag library, which includes a series of tag information. The tag library is the basic information for creating test cases.
[0068] S2: Create test cases based on the tag information in the tag library.
[0069] S3: Write the test cases created in S2 by recording (screen recording), identify the component operations in the test cases and convert them into labels; that is, in the process of writing test cases by screen recording, identify and record the clicked components and operations, and convert them into operation steps (label class set) that can be recognized by the test framework through the adapter.
[0070] S4: After S3 is recorded and custom assertion information is added, it is determined that the test case is written and stored.
[0071] S5: After testing by executing the test case saved in S4, the test result is obtained.
[0072] S1 and S2 are the basic steps for test execution;
[0073] The identification and labeling of the component operations in S3 are the main points of the present invention;
[0074] The custom assertion information in S4 can realize multiple assertion methods, which is the main inventive point of the present invention;
[0075] S5 is the test method corresponding to the test case obtained from S1 to S4.
[0076] S1 to S5 are described in detail below.
[0077] The tag library in S1 includes a tag information library and a tag response event library.
[0078] For the tag information library, it includes a series of tag classes and tag attributes.
[0079] For tag classes, according to functionality, tag classes include the following categories:
[0080] (1) The base class of all label objects, LabelOper, contains description information and error information attributes.
[0081] (2) The tag base class corresponding to the Java Swing component, JComponentOper, contains properties such as parent container id, component id, parent container object cache, current object cache, etc.
[0082] (3) Specific Java Swing basic component tags, such as the tag JTextFieldOper corresponding to the JText text box.
[0083] (4) Special functional tags: ClassOper (test class tag), TestCaseOper (test case tag), PubMethodOper (public method tag), PropertyValueOper (automatic property tag), ImportOper (reference public method tag), SleepOper (wait for response tag), AssertOper (assertion tag), CompareOper (expected value and actual value comparison tag), CustomOper (custom operation tag).
[0084] Tag attributes can be divided into the following categories according to their functionality:
[0085] (1) Basic attributes: basic attributes such as component tag ID and description information.
[0086] (2) Search attributes, which are used to locate components in the interface, such as the name, text, and index of component tags.
[0087] (3) Operation attributes are used to record the attributes of component operations, such as the clickcount attribute in JTreeOper, which records the number of mouse clicks on a tree node.
[0088] According to the role of tags in testing, tags can be divided into test tags and assertion tags. Test tags implement the IStepOper interface, and assertion tags implement the IAssert interface. When a tag implements both interfaces, it can be used for assertions and test operations. The JTableOper tag is the most commonly used tag that supports both test operations and assertions.
[0089] (2) The label response event library corresponds to the label information library. Each label corresponds to a label response event. LabelOperAction is used as the base class and is mapped one-to-one with labels with LabelOper as the base class. When the use case is running, the label object is automatically associated with the corresponding response event through the factory class, so that the search and operation of the specified component can be realized.
[0090] The difficulty of the problem in S3 is: Due to the particularity of Java Swing code, components drawn by developers themselves may appear in the application, and such components are difficult to identify according to the normal process; therefore, for this situation, there are two different processing flows for component identification, corresponding to the scenarios of successful and failed component operation identification, respectively, as follows:
[0091] The process of component operation recognition success and conversion into tags:
[0092] (1) Get the clicked component and obtain the current component and its operation event information from the listener.
[0093] (2) Determine the top-level container of the current component:
[0094] If the top-level container is a regular top-level container, such as TopComponent / JDialog / JFrame, the name attribute of the top-level container is recorded (the name is marked with name or title) and the top-level container ID is automatically generated. Then, the tag class corresponding to the current top-level container is created through the component-tag converter and cached to the top-level container tag object pool.
[0095] If the top-level container is a component-type container (it can be used as a component to trigger action events, and can be used as a container to carry other components. It can also be considered an unconventional top-level container, such as JTable), there is no need to identify the conversion again. The tag class of the top-level container can be directly obtained from the top-level container tag object pool (the reason why there is no need to identify the conversion here will be explained below).
[0096] (3) Obtain the key attributes of the current component by querying: the key attributes include the name of the current component, text, text floating prompt box textToolTip and interface layout.
[0097] In one embodiment, the process of obtaining the key attributes of the current component by querying includes: according to the query order, if any key attribute is queried, it is determined that the key attribute of the current component has been obtained, and at this time, the query operation is recorded and stopped; the query order is:
[0098] 1. Check whether the name attribute has a value.
[0099] 2. Check whether the text attribute has a value.
[0100] 3. Check whether the textToolTip attribute has a value.
[0101] 4. Parse the interface layout. If the direct parent container of the current component is a FormLayout layout, and there is text next to the component (left, right, top or bottom), get the text information.
[0102] (4) Determine the label of the current component according to its position in the top-level container, and set the label's PID (process identifier) to the top-level container ID; if the current component is a container-type component, such as JTableOpe, then the label of the current component needs to be cached in the top-level container label object pool. Here, it can be seen that the reason why the label can be directly obtained in the above point (2) is that the top-level container is a component-type container.
[0103] In one embodiment, the process of determining the label of the current component according to the position of the current component in the top-level container includes:
[0104] Search the DOM tree of the interface in order through the key attributes of the current component, and exclude invisible and uneditable interfaces and components.
[0105] Determine the set of components in the top-level container that have the same key attributes as the current component (the same judgment method is to compare the hash value and key attribute value of the component), create a label for the current component through the component-label converter according to the order of the current component in the component collection, and automatically generate the ID of the current component; set the PID attribute of the label to the ID of the top-level container, set the key attribute value and the position value Index in the parent container.
[0106] (5) Set the operation properties of the label of the current component.
[0107] In one embodiment, the process of setting the operation attribute of the label of the current component includes:
[0108] For components that support multiple clicks, the action property value is set to the number of mouse clicks;
[0109] For components that only have a single event, no special processing is required. For example, the JButton component corresponding to JButtonOper only has a click event, and there is no need to set additional operation properties.
[0110] For components that have multiple response events, the OperType attribute of the label of the current component is determined as the operation attribute by parsing the operation performed on the current component; for example, the JTable component corresponding to JTabelOper has the operation of right-clicking the table and selecting a cell.
[0111] Flow where component operation identification fails and is converted to a tag:
[0112] (1) Create a placeholder tag UnknowOper and automatically generate an ID. The existence of this tag can prevent the recording function from being affected by the unrecognizable components, so that the use case writing can be completed smoothly. These unrecognizable components can be processed after the entire use case recording is completed.
[0113] (2) Obtain and save the interface when the recognition fails, and mark the component that failed to be recognized in the interface.
[0114] In one embodiment, the above-mentioned interface where recognition fails and the process of marking the component where recognition fails in the interface include: taking a screenshot of the current interface where recognition fails through the Robot tool, and marking the component being operated at this time on the picture through the location recording function of the Robot, naming the picture with the ID of UnknowOper, and assigning the src (picture location) attribute of UnknowOper, where the attribute value is the absolute path of the picture; so that the picture and the corresponding functional component can be quickly located through the UnknowOper tag later.
[0115] (3) Based on the components marked in the interface when the recognition fails, change the placeholder labels to recognizable labels; this operation can be completed immediately or after the test case recording is completed.
[0116] In one embodiment, the process of modifying the placeholder label to a recognizable label according to the component marked in the interface when the recognition fails includes:
[0117] Modify the placeholder tag: locate the placeholder tag according to the graphical interface where the recognition failed, determine the (appropriate) component-type tag corresponding to the placeholder tag in the tag library, and replace the placeholder tag with the component-type tag; set properties for the component-type tag according to the component marked in the interface when the recognition failed (that is, adjust the properties based on "experience") until successful recognition can be achieved.
[0118] The above operations are generally aimed at the scenario where the basic type of components are misidentified by the screen recording tool. When it is difficult to set the properties (for example, no matter how the properties are set, they cannot be successfully identified), proceed to the following operations:
[0119] Customize the tag setting: locate the placeholder tag according to the graphical interface where the recognition failed, replace the placeholder tag with the custom operation tag in the tag library, set the perId (custom ID) and param attribute value (input parameter) of the custom operation tag, find the test class corresponding to the current custom operation tag in the test package according to perId, and execute the test operation through Java code.
[0120] Specifically, the process of finding the test class corresponding to the current custom operation tag in the test package according to the perId and performing the test operation through Java code includes:
[0121] Create a test class in the functional test package to inherit the ICustomExcute interface, implement the abstract method getPerId(), and set the return value to the perId in the CustomOper tag. Write Java code in the doAction() method to implement the interface test operation, and the value in the param attribute is the method input parameter. Example:
[0122] <CustomOper perId="Select port" param="Port 1">
[0123] The above is the XML script corresponding to the use case. The following is the code implementation corresponding to the "Select port" custom operation:
[0124]
[0125] In this way, it is possible to find the test class in the test package through the perId in the CustomOper tag and perform the test operation through Java code.
[0126] It should be noted that: the above custom setting tags can also be used directly, without waiting until the placeholder tag modification fails. The operation process of the custom setting tag is relatively complex and belongs to the "fallback" solution when the placeholder tag modification fails.
[0127] From this, it can be seen that the present invention can comprehensively and accurately set tags for components with recognition failures by manually adjusting the tags and the CustomOper tag, achieving full-scenario coverage of the test.
[0128] The process of adding custom assertion information in S4 includes:
[0129] Add the following tags:
[0130] (1) The assertion flag tag AssertOper used to represent the assertion operation. This tag has no actual function. The only use is that any tag under this tag is only used for assertion operations. Example:
[0131] <AssertOper discription="Assertion">
[0132] <JTextFieldOper pid="Top-level container TC" id="actureValue" name="Actual result" discription= "Get the actual result" / >
[0133] <CompareOper cType="equal" preValue="0" actureValue="%actureValue%" failMsg="The actual value does not match the expected value" discription="Output the assertion result" / >
[0134]
[0135] The above is an example of an XML test case script. All the steps within the AssertOper tag are performing assertion operations.
[0136] All supported component tag classes under AssertOper inherit the IAssertOper interface, and the component ID is bound to the component value when completing the assertion in the doAssert() method.
[0137] (2) The result comparison tag CompareOper used to compare the actual value of the component obtained according to the component ID with the set expected value to obtain the assertion result; this tag supports obtaining the actual value of the component through the component ID, supports setting the expected value, and provides four determination methods for whether the actual value is empty, whether the actual value is greater than / less than / equal to the expected value, and can cover most test scenarios required in daily life.
[0138] (3) The custom assertion tag CustomOper used to implement the assertion operation through code; CustomOper inherits both the IAssertOper interface and the IStepOper interface, so CustomOper can also be used as an assertion tag. Set the perId and param attribute values of CustomOper, create a test class in the functional test package that inherits the ICustomAssert interface, implement the abstract method getPerId(), and set the return value to the perId in the CustomOper tag. Write Java code in the doAssert() method to implement the interface assertion operation, and the value in the param attribute is the method input parameter. Through the supplement of custom assertions, full-scenario assertions for functional tests can be supported.
[0139] It can be seen from this that the present invention provides multiple assertion implementation methods and also supports custom assertions. Furthermore, it realizes a comprehensive assertion of the program and can handle more and more complex scenarios.
[0140] The execution mechanism for executing the test case in S5 is as follows:
[0141] Read the stored test case files and parse them into the corresponding type of LaberOper tag objects; cache the test case pool according to the class-use case-step hierarchy. There is a use case tag set in a class tag, and there is a step tag set in a use case tag set.
[0142] When PubMethodOper exists, PubMethodOper needs to be stored separately in the public method cache.
[0143] Query the use case that needs to be run this time in the cached use case pool, pass TestCaseOper to the label execution factory class LaberOperFactory, LaberOperFactory finds the corresponding response event class LaberOperAction according to the label type, and calls the doOper() method to run the use case.
[0144] When executing use cases, you may encounter the following scenarios, which require different processing:
[0145] (1) Conventional component-type tags: The use case is executed normally to search and operate the components.
[0146] (2) ImportOper tag, query the corresponding PubMethodOper in the public method cache, call doOper() method to execute the set of operation steps in PubMethodOper in the class. The following are the operations performed by ImportOper:
[0147] @ServiceProvider(service=LabelOperAction.class)
[0148] public class ImportOperAction extends LabelOperAction <importoper>{
[0149] @Override
[0150] public boolean excute(){
[0151] ConsoleUtil.write("Find public method " + labelOper.Id);
[0152] PubMethodOper methodOper = TestCaseInfoCache.getPubMethod(labelOper.Id);
[0153] if (null == methodOper) {
[0154] labelOper.setErrormsg("Public method not found for " + labelOper.Id);
[0155] return false;
[0156] }
[0157] ConsoleUtil.write("Execute public method " + labelOper.Id);
[0158] return methodOper.doOper();
[0159] }
[0160] }
[0161] The following is an example of the combined use of the ImportOper tag and the PubMethodOper tag:
[0162] <ImportOper linkId = "Open business management interface">
[0163] <PubMethodOper id = "Open business management interface" discription = "Execute the public method for opening the business management interface"> ...
[0165] <Operation step label / > ...
[0167]
[0168] Among them, the linkId of ImportOper needs to be the same as the id of PubMethodOper to complete the public method call.
[0169] (3) AssertOper tag, executes the LaberOper tag set of assertions in AssertOper in sequence, and calls the doAssert() method of the corresponding LaberOperAction.
[0170] The test results in S5 include coverage result output and use case test results.
[0171] The coverage result output is achieved by embedding the Jacoco coverage tool into the test writing and running process, setting the default port, supporting the output of the coverage of the operation steps during the screen recording process, and automatically generating the code coverage of the running use case when the use case is finished running, so that R&D personnel can adjust the use case in time according to the coverage to ensure that the use case covers more comprehensive scenarios.
[0172] The test case test results include screenshots of failed cases and test case running result records.
[0173] (1) The method used to take screenshots of failed use cases is to open a new thread to record the interface DOM tree when the failure occurs, draw the DOM tree on a new cavas, and then export the cavas as a png image for saving. This avoids the problem of black screen when taking screenshots of third-party tools such as robot when the test machine is disconnected. At the same time, it will not affect the currently running functional tests. The screenshots of failed use cases are named after the use case name.
[0174] (2) Test case running result record: After the test is completed, the complete execution log information will be output, showing the execution status of the test cases every day in the form of a table. The table contains information such as the test case name, author, success, and failure reason. This helps to better locate the failed test cases.
[0175] The test process of the above method is described below in terms of timing through a specific embodiment.
[0176] S1: Create a tag library, which includes a series of tag information. The tag library is the basic information for creating test cases. Go to S2.
[0177] S2: Create test cases based on the tag information in the tag library and go to S3.
[0178] S3: Write the test case created in S2 by recording (screen recording), identify the component operations in the test case and convert them into labels, and go to S4 after the recording is completed.
[0179] See also Figure 2 As shown in the figure, the specific process of identifying a component operation and converting it into a label in S3 includes:
[0180] S301: Determine whether the current component is successfully identified, if so, go to S302, otherwise go to S307.
[0181] S302: Determine the label and ID of the top-level container of the current component, and go to S303.
[0182] If the top-level container is a regular top-level container, create the tag class and policy container ID corresponding to the top-level container and set the properties and cache in the above manner;
[0183] If the top-level container is a component-type container, the tag class of the top-level container is obtained from the top-level container tag object pool.
[0184] S303: Create a tag corresponding to the current component and set key attributes, set the PID of the tag to the top-level container ID, and go to S304.
[0185] S304: Determine whether the current component is a container-type component. If so, go to S305; otherwise, go to S306.
[0186] S305: Cache the tag of the current component into the top-level container tag object pool, and go to S306.
[0187] S306: Set the operation attributes of the label of the current component, and go to S311.
[0188] S307: Generate a placeholder tag UnknowOper, take a screenshot of the interface when the recognition fails and set corresponding attributes (image name, search path, etc.), and go to S308.
[0189] S308: Determine whether the current component can be identified by modifying the placeholder tag. If so, go to S309; otherwise, go to S310.
[0190] S309: Modify the placeholder tag by modifying the placeholder tag, and go to S311.
[0191] S310: Replace the placeholder label by customizing the label setting method, and go to S311.
[0192] S311: Add a waiting response tag (SleepOper) according to the operator's operation speed, and set the waiting time attribute.
[0193] S4: After adding the custom assertion information, confirm that the test case is written and store the test case.
[0194] See also Figure 3 As shown, the process of S4 includes:
[0195] S401: Add an assertion mark label AssertOper, a result comparison label CompareOper, and a custom assertion label CustomOper, and go to S402.
[0196] S402: Determine the assertion scenario: If it is a simple assertion scenario, go to S403; if it is a complex assertion scenario, go to S404.
[0197] S403: Use the result comparison tag CompareOper to compare the actual value and the expected value, and go to S405.
[0198] S404: Use the custom assertion tag CustomOper to complete the assertion in a coded form, and go to S405.
[0199] S405: After the test case is written, the tag class set generated by the test case is written into a corresponding XML file through reflection for storage.
[0200] S5: Execute the test case saved in S4 and obtain the test result.
[0201] See also Figure 4 As shown, the process of S5 includes:
[0202] S501: Read and parse the XML file of the test case, obtain the corresponding tag class, obtain all public method objects PubMethodOper, cache them, and go to S502.
[0203] S502: Cache the use case pool according to the relationship between class-use case-step, and go to S503.
[0204] S503: Query the use case that needs to be run in the use case pool, execute the use case through the factory class, and go to S504.
[0205] S504: Execute the test steps in the test case label in sequence. If an import public method label (ImportOper) is identified during the execution, go to S505; if an assertion mark label AssertOper is identified, go to S506.
[0206] S505: Query the method pool for the public method to be introduced for execution, and then go to S507.
[0207] S506: Execute the assertion steps in the assertion tag in order, and go to S507.
[0208] S507: After the test case is executed, the test result is output.
[0209] It can be seen that the present invention achieves comprehensive coverage of test scenarios by providing a set of tag libraries and a complete component operation conversion process; realizes no-dead-angle assertions of the program by providing a variety of assertion implementation methods; ensures the smooth operation of functional tests by providing a complete set of use case execution processes; and avoids the problem of black screen screenshots by third-party tools through a customized failure screenshot method.
[0210] At the same time, the present invention also has the following advantages:
[0211] Real-time monitoring of use case coverage allows developers to write efficient use cases, optimize useless code, and effectively improve use case and code quality;
[0212] Log output is clearer, and the log contains the properties and action information of the operation interface components, which makes it faster to locate problems;
[0213] It has good versatility and extensibility, and can achieve full coverage of source code, so that recognizable components can be recorded, and unrecognizable components or temporarily blocked functions can also be triggered through code;
[0214] The writing of basic use cases does not require language knowledge, and the entry threshold is low. The most complex use cases only require Java knowledge, so Java Swing application developers can get started faster.
[0215] In a second aspect, an embodiment of the present application further provides a testing system for Java Swing application functions, which is used to implement the above method.
[0216] Specifically, the system includes:
[0217] The tag library creation module is used to create the above tag library.
[0218] The test case creation module is used to create test cases according to the tag information in the tag library.
[0219] The test case writing module is used to write the created test cases by recording.
[0220] The test case writing module includes:
[0221] (1) A component identification processing module is used to identify component operations in test cases during recording and convert them into labels.
[0222] The specific component identification processing modules include:
[0223] The basic component operation identification processing module is used to: execute the process of successfully identifying the component operation in the above method and converting it into a label.
[0224] The complex component operation identification processing module is used to: execute the process of component operation identification failure and converting it into a label in the above method.
[0225] (2) Assertion module, which is used to add custom assertion information.
[0226] The test case execution module is used to execute the test cases written by the test case writing module and obtain the test results.
[0227] In a third aspect, an embodiment of the present application provides a testing device for Java Swing application functions. The testing device for Java Swing application functions may be a personal computer (PC), a notebook computer, a server, or other device with data processing functions.
[0228] Reference Figure 5 , Figure 5 The hardware structure diagram of the testing device for Java Swing application functions involved in the embodiment of the present application is shown in FIG. In the embodiment of the present application, the testing device for Java Swing application functions may include a processor, a memory, a communication interface, and a communication bus.
[0229] The communication bus may be of any type and is used to interconnect the processor, the memory, and the communication interface.
[0230] The communication interface includes an input / output (I / O) interface, a physical interface, and a logical interface, etc., which are used to interconnect devices inside the test equipment for Java Swing application functions, and an interface for interconnecting the test equipment for Java Swing application functions with other devices (such as other computing devices or user devices). The physical interface can be an Ethernet interface, an optical fiber interface, an ATM interface, etc.; the user device can be a display, a keyboard, etc.
[0231] The memory can be various types of storage media, such as random access memory (RAM), read-only memory (ROM), non-volatile RAM (NVRAM), flash memory, optical storage, hard disk, programmable ROM (PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM), etc.
[0232] The processor may be a general-purpose processor, and the general-purpose processor may call the test program for the Java Swing application function stored in the memory, and execute the test method for the Java Swing application function provided by the embodiment of the present application. For example, the general-purpose processor may be a central processing unit (CPU). The method executed when the test program for the Java Swing application function is called may refer to the various embodiments of the test method for the Java Swing application function of the present application, which will not be repeated here.
[0233] Those skilled in the art will understand that Figure 5 The hardware structure shown in the figure does not constitute a limitation on the present application, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0234] In a fourth aspect, an embodiment of the present application also provides a computer-readable storage medium.
[0235] The computer-readable storage medium of the present application stores a test program for Java Swing application functions, wherein when the test program for Java Swing application functions is executed by a processor, the steps of the test method for Java Swing application functions as described above are implemented.
[0236] Among them, the method implemented when the test program for Java Swing application functions is executed can refer to the various embodiments of the test method for Java Swing application functions of this application, and will not be repeated here.
[0237] It should be noted that the serial numbers of the above-mentioned embodiments of the present application are only for description and do not represent the advantages or disadvantages of the embodiments.
[0238] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD) as described above, and includes a number of instructions for a terminal device to execute the methods described in each embodiment of the present application.
[0239] The terms "including" and "having" and any variations thereof in the specification and claims of this application and the above-mentioned drawings are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices. The terms "first", "second" and "third" are used to distinguish different objects, etc., and do not represent a sequence, nor do they limit "first", "second" and "third" to different types.
[0240] In the description of the embodiments of the present application, "exemplary", "for example" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary", "for example" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary", "for example" or "for example" is intended to present related concepts in a specific way.
[0241] In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; the "and / or" in the text is merely a description of the association relationship of associated objects, indicating that three relationships may exist, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" refers to two or more than two.
[0242] In some processes described in the embodiments of the present application, multiple operations or steps that appear in a specific order are included, but it should be understood that these operations or steps may not be executed in the order in which they appear in the embodiments of the present application or in parallel, and the sequence number of the operation is only used to distinguish the different operations, and the sequence number itself does not represent any execution order. In addition, these processes may include more or fewer operations, and these operations or steps may be executed in sequence or in parallel, and these operations or steps may be combined.
[0243] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD) as described above, and includes a number of instructions for a terminal device to execute the methods described in each embodiment of the present application.
[0244] The above are only specific implementations of the embodiments of the present invention, but the protection scope of the embodiments of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in the embodiments of the present invention, and these modifications or replacements should be included in the protection scope of the embodiments of the present invention. Therefore, the protection scope of the embodiments of the present invention shall be based on the protection scope of the claims.< / importoper>
Claims
1. A method for testing the functionality of a Java Swing application, characterized in that: The method comprises the following steps: Flow where component operation identification fails and is converted to a tag: Create a placeholder tag and generate an ID; Obtain an interface where identification fails, and mark the component where identification fails in the interface; Change the placeholder label to a recognizable label based on the component marked in the interface when recognition fails.
2. The method for testing the function of a Java Swing application program as claimed in claim 1, characterized in that: The process of modifying the placeholder label to a recognizable label according to the component marked in the interface when the recognition fails includes: The placeholder tag is located according to the interface where the recognition fails, the component-type tag corresponding to the placeholder tag is determined, and the placeholder tag is replaced with the component-type tag; and properties are set for the component-type tag according to the component marked in the interface when the recognition fails until successful recognition is achieved.
3. The method for testing the function of a Java Swing application program according to claim 1 or 2, characterized in that: The process of modifying the placeholder tag to a recognizable tag based on the component marked in the interface when the recognition fails includes: locating the placeholder tag according to the interface where the recognition fails, replacing the placeholder tag with a custom operation tag, setting the ID and attributes of the custom operation tag, searching for the corresponding test class according to the ID of the custom operation tag, and executing the test operation through Java code.
4. The method for testing the function of a Java Swing application program as claimed in claim 3, characterized in that: The method further comprises the following steps: The process of component operation recognition success and conversion into tags: Determine the top-level container of the current component: If the top-level container is a regular top-level container, record the name attribute of the top-level container and generate the top-level container ID, then create and cache the tag class corresponding to the current top-level container; if the top-level container is a component-type container, retrieve the tag class of the top-level container from the cache; Get the key attributes of the current component, including the name of the current component, text, text floating prompt box textToolTip and interface layout; Determine the label of the current component according to its position in the top-level container, and set the label's PID to the top-level container ID; if the current component is a container-type component, cache the label of the current component; Sets the action property of the current component's label.
5. The method for testing the function of a Java Swing application program as claimed in claim 4, characterized in that: The process of obtaining the key attributes of the current component includes: According to the query order, if any key attribute is found, it is determined that the key attribute of the current component has been obtained; the query order is: Query the name attribute, text attribute, and textToolTip attribute in turn, and finally parse the interface layout. If the direct parent container of the current component is a FormLayout layout and there is text next to the component, obtain the text information.
6. The method for testing the function of a Java Swing application program as claimed in claim 4, characterized in that: The process of determining the label of the current component according to the position of the current component in the top-level container includes: Determine the set of components in the top-level container that have the same key attributes as the current component, create a label for the current component and automatically generate an ID for the current component based on the order of the current component in the set of components; The process of setting the operation attribute of the label of the current component includes: For components that support multiple clicks, the action property value is set to the number of mouse clicks; For a component that has multiple response events, the OperType attribute of the tag of the current component is determined as the operation attribute by parsing the operation performed on the current component.
7. The method for testing the function of a Java Swing application program as claimed in claim 3, characterized in that: The method also includes the following steps: adding custom assertion information; Custom assertion information includes: Assertion flag tag, used to indicate that an assertion operation is to be performed; The result comparison tag is used to compare the actual value of the component obtained according to the component ID with the set expected value to obtain the assertion result; Custom assertion tags are used to implement assertion operations through code.
8. The method for testing the function of a Java Swing application program as claimed in claim 3, characterized in that: The method further comprises the following steps: creating a tag library; The tag library includes a tag information library and a tag response event library; The tag information base includes tag classes and tag attributes; The tag class includes: the base class of tag objects, the tag base class corresponding to the Java Swing component, the Java Swing basic component tag and the functional tag; Functional tags include: test class tags, test case tags, public method tags, automatic attribute tags, reference public method tags, assertion tags, expected value and actual value comparison tags, and custom operation tags; Tag attributes include basic attributes, search attributes, and operation attributes; The tag response event library includes a tag response event corresponding to each tag in the tag information library.
9. A testing system for Java Swing application functions, characterized in that: The system includes a component identification processing module, which is used to: execute the process of component operation identification failure and conversion into a label as described in any one of claims 1 to 8.
10. The testing system for Java Swing application functions according to claim 9, characterized in that: The system also includes: A tag library creation module, which is used to: create the tag library described in claim 8; A test case creation module is used to: create test cases according to tag information in the tag library; The test case writing module is used to: write the created test cases by recording; The test case writing module includes the component identification processing module and the assertion module: The component identification processing module is also used to: execute the process of successfully identifying the component operation and converting it into a label as described in any one of claims 4 to 8; The assertion module is used to: add the custom assertion information described in claim 7 or 8; The test case execution module is used to execute the test cases written by the test case writing module and obtain the test results.