CN107704374B - Test method and device - Google Patents

Test method and device Download PDF

Info

Publication number
CN107704374B
CN107704374B CN201610643110.9A CN201610643110A CN107704374B CN 107704374 B CN107704374 B CN 107704374B CN 201610643110 A CN201610643110 A CN 201610643110A CN 107704374 B CN107704374 B CN 107704374B
Authority
CN
China
Prior art keywords
code file
language
file
recognized
code
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201610643110.9A
Other languages
Chinese (zh)
Other versions
CN107704374A (en
Inventor
陈显金
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201610643110.9A priority Critical patent/CN107704374B/en
Publication of CN107704374A publication Critical patent/CN107704374A/en
Application granted granted Critical
Publication of CN107704374B publication Critical patent/CN107704374B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing

Abstract

The application discloses a testing method and a testing device. One embodiment of the method comprises: acquiring a code file path, a code file type and a language to be identified; searching each code file under the code file path, and selecting a code file with the same file type as the code file to be detected; reading the content of the code file to be identified, and matching characters matched with the language to be identified in the content of the code file to be identified by using a regular expression; and generating a test report in response to matching the characters which are matched with the language to be recognized. The embodiment reduces the missing detection rate and improves the testing efficiency.

Description

Test method and device
Technical Field
The application relates to the technical field of computers, in particular to the field of software testing, and particularly relates to a testing method and a testing device.
Background
At present, most of domestic developers use Chinese notes and Chinese prompts in the programming process. If the developed system is used outside the continental china or the software is to make multinational language versions, then we must screen out the chinese language and make translation modifications. Similarly, other non-english countries develop software that also has this problem, such as developers using korean, japanese, etc. during programming. An efficient and fast method is needed to quickly identify these non-english language words.
Generally, there are two methods for testing text in a code:
white box testing: the method mainly depends on a developer to statically walk through the code and judge whether the characters matched with the language to be recognized are comments or prompts, outputs and the like used in the code.
Black box testing: the method mainly comprises the steps that a tester tests in a specific testing stage to check whether characters matched with the language to be recognized exist in each page element of a page and check whether characters matched with the language to be recognized exist in normal prompt and abnormal prompt in a business process.
Although both the two testing methods can achieve a certain testing effect, the white box testing method is adopted, so that the static code walkthrough of developers is time-consuming, and especially under the condition that a plurality of codes are quoted by other projects, the walkthrough time is too high in cost, and the missing testing rate is higher; the black box test method is also high in missing rate, because the black box test can expose characters and part of prompt messages on part of pages, most of abnormal prompt messages are difficult to find.
In summary, the conventional test method has high test leakage rate and low test efficiency.
Disclosure of Invention
It is an object of the present application to provide an improved testing method and apparatus to solve the technical problems mentioned in the background section above.
In a first aspect, the present application provides a method of testing, the method comprising: acquiring a code file path, a code file type and a language to be identified; searching each code file under the code file path, and selecting a code file with the same file type as the code file to be detected; reading the content of the code file to be identified, and matching characters matched with the language to be identified in the content of the code file to be identified by using a regular expression; and generating a test report if the characters matched with the language to be recognized are matched.
In some embodiments, the reading the content of the code file to be recognized, and matching the characters matching the language to be recognized in the content of the code file to be recognized by using a regular expression includes: matching the content of each line of the code file to be detected by using a regular expression, determining whether the line has characters matched with the language to be recognized, and if so, recording at least one of the following items: the characters matched with the language to be recognized, the file name and the path of the file where the characters matched with the language to be recognized are located, and the line number of the line where the characters matched with the language to be recognized are located.
In some embodiments, the reading the content of the code file to be recognized, and matching the characters matching the language to be recognized in the content of the code file to be recognized by using a regular expression includes: matching the content of each line of the code file to be detected by using a regular expression, determining whether the line has characters matched with the language to be recognized, and if so, further determining whether the characters matched with the language to be recognized are the characters of the annotation type; in response to determining that the character matching the language to be recognized is not a character of the annotation type, recording at least one of: the characters matched with the language to be recognized, the file name and the path of the file where the characters matched with the language to be recognized are located, and the line number of the line where the characters matched with the language to be recognized are located.
In some embodiments, the reading the content of the code file to be recognized, and matching the characters matching the language to be recognized in the content of the code file to be recognized by using a regular expression includes: and in response to determining that the characters matched with the language to be recognized are the characters of the annotation type, continuing to read the content of the code file to be recognized.
In some embodiments, before the reading the content of the code file to be recognized and matching the characters matching the language to be recognized in the content of the code file to be recognized by using a regular expression, the method further includes: and determining whether the coding mode of the code file to be tested is uniform code coding, and if not, converting the coding mode of the code file to be tested into uniform code coding.
In some embodiments, the code file path is a path of a distributed version control system or a native code folder path.
In some embodiments, before searching for each code file in the code file path and selecting a code file with a file type that is the same as the code file type as a code file to be tested, the method further includes: determining whether the path of the code file is the path of the distributed version control system, if so, downloading the code file to the local from a server indicated by the path of the distributed version control system; and replacing the acquired path of the distributed version control system by the path of the downloaded code file at the local.
In some embodiments, the content of the test report includes at least one of: the method comprises the steps of matching out characters matched with the language to be recognized, the file name and the path of a file where the matched characters matched with the language to be recognized are located, and the line number of lines where the matched characters matched with the language to be recognized are located.
In a second aspect, the present application provides a test apparatus, the apparatus comprising: the system comprises an acquisition unit, a recognition unit and a recognition unit, wherein the acquisition unit is configured to acquire a code file path, a code file type and a language to be recognized; the selection unit is configured to search each code file under the code file path, and select a code file with the same file type as the code file to be detected; the matching unit is configured to read the content of the code file to be identified and match characters matched with the language to be identified in the content of the code file to be identified by using a regular expression; and the generating unit is used for responding to the matched characters with the language to be recognized and then generating a test report.
In some embodiments, the matching unit comprises: the matching subunit is configured to match the content of each line of the code file to be identified by using a regular expression, determine whether the line has characters matched with the language to be identified, and if so, record at least one of the following items: the characters matched with the language to be recognized, the file name and the path of the file where the characters matched with the language to be recognized are located, and the line number of the line where the characters matched with the language to be recognized are located.
In some embodiments, the matching unit comprises: the determining subunit is configured to match the content of each line of the code file to be detected by using a regular expression, determine whether the line has characters matched with the language to be recognized, and if so, further determine whether the characters matched with the language to be recognized are characters of an annotation type; a first processing subunit configured to, in response to determining that the character matching the language to be recognized is not a character of an annotation type, record at least one of: the characters matched with the language to be recognized, the file name and the path of the file where the characters matched with the language to be recognized are located, and the line number of the line where the characters matched with the language to be recognized are located.
In some embodiments, the matching unit comprises: and the second processing subunit is configured to, in response to determining that the character matched with the language to be recognized is a character of an annotation type, continue to read the content of the code file to be detected.
In some embodiments, the apparatus further comprises: and the conversion unit is configured to determine whether the coding mode of the code file to be tested is uniform code coding, and if not, convert the coding mode of the code file to be tested into uniform code coding.
In some embodiments, the code file path is a path of a distributed version control system or a native code folder path.
In some embodiments, the apparatus further comprises: the path determining unit is configured to determine whether the code file path is a path of the distributed version control system, and if so, download the code file to the local from a server indicated by the path of the distributed version control system; and the replacing unit is configured for replacing the acquired path of the distributed version control system by the downloaded code file at the local path.
In some embodiments, the content of the test report includes at least one of: the method comprises the steps of matching out characters matched with the language to be recognized, the file name and the path of a file where the matched characters matched with the language to be recognized are located, and the line number of lines where the matched characters matched with the language to be recognized are located.
In a third aspect, an embodiment of the present application provides an electronic device, including: one or more processors; storage means for storing one or more programs; when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the method as described in any implementation manner of the first aspect.
In a fourth aspect, the present application provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method as described in any implementation manner of the first aspect.
According to the testing method and the testing device, the code file path, the code file type and the language to be recognized are obtained, so that each code file can be conveniently searched under the code file path, the code file with the same file type as the obtained code file type is selected as the code file to be tested, the content of the code file to be tested is read, the characters matched with the language to be recognized are matched in the content of the code file to be tested by using the regular expression, and finally the testing report is generated after the content of the code file to be tested is matched and the characters matched with the language to be recognized are matched, so that the regular expression is effectively used, the missing rate is reduced, and the testing efficiency is improved.
Drawings
Other features, objects and advantages of the present application will become more apparent upon reading of the following detailed description of non-limiting embodiments thereof, made with reference to the accompanying drawings in which:
FIG. 1 is an exemplary system architecture diagram in which the present application may be applied;
FIG. 2 is a flow diagram of one embodiment of a testing method according to the present application;
FIG. 3 is a schematic diagram of an application scenario of a test method according to the present application;
FIG. 4 is a flow chart of yet another embodiment of a testing method according to the present application;
FIG. 5 is a schematic block diagram of one embodiment of a test apparatus according to the present application;
fig. 6 is a schematic structural diagram of a computer system suitable for implementing a terminal device according to an embodiment of the present application.
Detailed Description
The present application will be described in further detail with reference to the following drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the relevant invention and not restrictive of the invention. It should be noted that, for convenience of description, only the portions related to the related invention are shown in the drawings.
It should be noted that the embodiments and features of the embodiments in the present application may be combined with each other without conflict. The present application will be described in detail below with reference to the embodiments with reference to the attached drawings.
Fig. 1 shows an exemplary system architecture 100 to which embodiments of the testing method or testing apparatus of the present application may be applied.
As shown in fig. 1, the system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 serves as a medium for providing communication links between the terminal devices 101, 102, 103 and the server 105. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The user can use the terminal devices 101, 102, 103 to make a communication connection with the server 105 via the network 104 to download a desired code file from the server 105. The terminal devices 101, 102, 103 may be installed with various communication client applications, such as a web browser application, a search application, an instant messaging tool, and the like, and may also be installed with various testing tools.
The terminal devices 101, 102, 103 may be various electronic devices having a display screen and supporting testing of code files, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 105 may be a server that provides various services, such as a distributed version control system server that provides support for test tools installed on the terminal devices 101, 102, 103. A distributed version control system repository may be built on the distributed version control system server, and the distributed version control system repository may have code files required by the terminal devices 101, 102, and 103.
It should be noted that the test method provided in the embodiment of the present application is generally executed by the terminal devices 101, 102, and 103, and accordingly, the test apparatus is generally disposed in the terminal devices 101, 102, and 103.
It should be understood that the number of terminal devices, networks, and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation. Here, in the case where the code file path acquired by the terminal apparatuses 101, 102, 103 is a local code folder path, the server 105 may not be necessary.
With continued reference to FIG. 2, a flow 200 of one embodiment of a testing method according to the present application is shown. The testing method comprises the following steps:
step 201, obtaining a code file path, a code file type and a language to be identified.
In this embodiment, the electronic device (for example, the terminal devices 101, 102, 103 shown in fig. 1) on which the test method operates may acquire the code file path, the code file type, and the language to be recognized configured by the user without network connection. As an example, the electronic device may provide an interface for a user to input a code file path, a code file type, and a language to be recognized on the interface, and after the user inputs and submits the content, the electronic device may obtain the code file path, the code file type, and the language to be recognized that are input by the user.
Optionally, the code file path acquired by the electronic device may be a path of a distributed version control system or a local code folder path.
Optionally, the code file type acquired by the electronic device may be a java type, a js type, a vm type, an html type, and the like. The electronic device may set a default code file type, such as java type, js type, and vm type.
Optionally, the language to be recognized acquired by the electronic device may be chinese, japanese, korean, or the like. The user can set the language according to the actual requirement. As an example, if a system developed by a chinese developer is to be oriented to the korean market, chinese contained in the system needs to be translated into korean; when a user wants to confirm whether the system has the problem of missing the page, the code file of the system can be tested; the user can input 'Chinese' in the language area to be recognized on the interface provided by the electronic equipment, and the Chinese is taken as the language to be recognized. The electronic device may set a default language, such as chinese to the default language.
In some optional implementations of the embodiment, the electronic device may further set a default retrieval type, for example, may set a default retrieval of all characters. Here, the user may also set whether to retrieve the character of the annotation type according to the actual needs of the user. The characters of the annotation type may generally be understood as characters which start with "/" or "//".
Step 202, searching each code file under the code file path, and selecting the code file with the same file type as the acquired code file as the code file to be tested.
In this embodiment, based on the code file path, the code file type, and the language to be recognized that are acquired in step 201, the electronic device may recursively traverse all the code files in the code file path, and select a code file having a file type that is the same as the acquired code file type as a code file to be recognized.
In some optional implementation manners of this embodiment, before searching for each code file in the code file path, the electronic device may first determine whether the code file path is a path of a distributed version control system. If the code file path is the path of the distributed version control system, the electronic device can download the required code file from a server indicated by the path of the distributed version control system to a local cache or a hard disk; and then analyzing the local path of the downloaded code file, and replacing the acquired path of the distributed version control system with the local path of the downloaded code file. If the acquired code file path is a local code folder path, the electronic device may not perform a processing operation on the acquired code file path.
In some optional implementation manners of this embodiment, the electronic device may generate a file set to store the file name and the path of the code file to be tested. In addition, when the number of the code files to be tested is more than 1, the file names in the file set may be sorted, for example, sorted according to upgrade or sorted according to downgrade.
Step 203, reading the content of the code file to be identified, and matching characters matched with the language to be identified in the content of the code file to be identified by using the regular expression.
In this embodiment, based on the code file to be tested determined in step 202, the electronic device may read the content of the code file to be tested, and may match characters matching the language to be recognized in the content of the code file to be tested by using a regular expression.
In some optional implementation manners of this embodiment, before the electronic device reads the content of the code file to be detected and matches a character matched with a language to be recognized in the content of the code file to be detected by using a regular expression, it may be determined whether a coding manner of the code file to be detected is Unicode (Unicode) coding; if not, the coding mode of the code file to be tested can be converted into a uniform code; if so, the encoding mode of the code file to be tested is not processed. For example, the electronic device may determine whether the code file to be tested is Unicode by determining the first two bytes of the code file to be tested, for example, if the first two bytes are FFFE, it may be determined that the coding mode of the code file to be tested is Unicode; the electronic equipment can also search which coding mode the characters in the code file to be detected is similar to in a preset coding library, if the coding mode with the similarity of the characters in the code file to be detected being more than 80% is searched out, the coding mode can be considered as the coding mode of the code file to be detected, and then whether the coding mode of the code file to be detected is Unicode coding or not can be determined.
In some optional implementations of the embodiment, the electronic device may match all characters in the code file to be tested by default. The electronic equipment can adopt a regular expression to recognize the content of the code file to be detected line by line word by word and match characters matched with the language to be recognized. As an example, if the language to be recognized is chinese, a regular expression [ \ u4e00- \ u9fa5] may be adopted to recognize chinese characters line by line in the content of the code file to be recognized; because Chinese is a double-byte character, the electronic equipment can also adopt a regular expression [ ^ x00- \\ xff ] to identify the double-byte character in the content of the code file to be tested. If the electronic equipment matches the characters matched with the language to be recognized, at least one of the following items is recorded: the matched characters matched with the language to be recognized, the file name and the path of the file where the matched characters are located, and the line number of the matched characters located.
In some optional implementation manners of this embodiment, if the file set for storing the file name and the path of the code file to be tested is generated in step 202, the electronic device may test each of the code files to be tested by: determining whether the set of files is empty; responding to the fact that the file set is not empty, the electronic equipment reads information of a code file to be tested from the file set, and the code file to be tested is taken out according to the information of the code file to be tested; then determining whether the coding mode of the code file to be tested is uniform code coding; if the coding mode of the code file to be tested is not uniform code, converting the coding mode of the code file to be tested into uniform code, and then reading the content of the code file to be tested; if the coding mode of the code file to be tested is uniform code coding, reading the content of the code file to be tested; then, matching the characters matched with the language to be recognized line by line and word by word in the content of the code file to be detected by utilizing a regular expression; if a character matching the language to be recognized is matched, at least one of the following is recorded: the matched characters matched with the language to be recognized, the file name and the path of the file where the matched characters are located, and the line number of the matched characters located; and after matching all the characters in the code file to be detected, deleting the information of the code file to be detected from the file set.
And step 204, responding to the matched characters with the language to be recognized, and generating a test report.
In this embodiment, in response to that the characters matching the language to be recognized are matched in step 203, the electronic device may acquire the record information of the characters matching the language to be recognized after matching the content of the code file to be tested, and generate a test report after processing the acquired record information. By way of example, the electronic device may integrate the acquired recording information to generate a test report of a text document type, and store the test report to a specified path for a user to view.
Optionally, the content of the test report may include at least one of: the matched characters matched with the language to be recognized, the file name and the file type of the file where the matched characters are located, and the line number of the matched characters located.
Optionally, the file type of the test report may be an html type, a text document type, or another file type that the user can normally open and view.
In some optional implementations of the embodiment, for the characters matching the language to be recognized, which are continuously displayed in the same row, the electronic device may record the characters in the same piece of information in the generated test report. Java code files, the electronic device matches 5 chinese characters, namely "network", "connection", "exception" and "normal", and records information related to the chinese characters respectively; the electronic equipment can analyze the information of the Chinese characters by acquiring the information of the Chinese characters; if the electronic device determines that the chinese characters are displayed consecutively in the same row, the chinese characters may be merged into a string "network connection exception"; and displaying the complete character string 'network connection abnormity' in one piece of information.
With continued reference to fig. 3, fig. 3 is a schematic diagram of an application scenario of the test method according to the present embodiment. In the application scenario of fig. 3, a user first inputs a code file path "C: \" files ", a code file type" java, js, html, vm "and a language to be recognized" chinese "through an interface provided by a client, and submits the input information to the client; then, the client can acquire the code file path, the code file type and the language to be identified submitted by the user; then, the client can search each code file from the code file path 'C: \ files', and code files of the file types of 'java', 'js', 'html' and 'vm' are selected as code files to be detected; then, the client can read the content of the code file to be identified, and can match characters matched with the language to be identified in the content of the code file to be identified by using a regular expression; finally, in response to the client matching the content of the code file to be tested and matching the characters matching the language to be recognized, the client may generate a test report, as shown by reference numeral 301, for the user to view.
According to the method provided by the embodiment of the application, the regular expression is used for matching the characters matched with the language to be recognized in the content of the code file to be detected, so that the missing detection rate is reduced, and the testing efficiency is improved.
With further reference to fig. 4, a flow 400 of yet another embodiment of a testing method is shown. The process 400 of the test method includes the following steps:
step 401, obtaining a code file path, a code file type and a language to be recognized.
In this embodiment, the electronic device (for example, the terminal devices 101, 102, 103 shown in fig. 1) on which the test method operates may acquire the code file path, the code file type, and the language to be recognized configured by the user without network connection. As an example, the electronic device may provide an interface for a user to input a code file path, a code file type, and a language to be recognized on the interface, and after the user inputs and submits the content, the electronic device may obtain the code file path, the code file type, and the language to be recognized that are input by the user.
Step 202, searching each code file under the code file path, and selecting the code file with the same file type as the acquired code file as the code file to be tested.
In this embodiment, based on the code file path, the code file type, and the language to be recognized acquired in step 201, the electronic device may recursively traverse all the code files in the code file path, and select a code file having a file type that is the same as the code file type as the code file to be recognized.
Step 403, reading the content of the code file to be identified, matching the content of each line of the code file to be identified by using the regular expression, and determining whether the line has characters matched with the language to be identified.
In this embodiment, based on the code file to be tested determined in step 402, the electronic device may read the content of the code file to be tested, and may match the content of each line of the code file to be tested by using a regular expression. For the content of each line in the code file to be tested, if the electronic device matches a character matching the language to be recognized in the line, it may be determined that the character matching the language to be recognized exists in the line, and step 404 is performed.
Step 404 further determines whether the character matching the language to be recognized is a character of the annotation type.
In this embodiment, for each line of content in the code file to be tested, in response to determining that there is a character matching the language to be recognized in step 403, the electronic device may further determine whether the character is a character of the annotation type. As an example, the electronic device may determine whether the character matching the language to be recognized is a character of the comment type by judging whether the character matching the language to be recognized starts with "/" or "//". If the character matching the language to be recognized is not a character of the annotation type, go to step 405; if yes, go to step 403 to continue reading the content of the code file to be tested.
In response to determining that the character matching the language to be recognized is not a character of the annotation type, at least one of: the matched characters matched with the language to be recognized, the file name and the path of the file where the matched characters are located, and the line number where the matched characters are located.
In this embodiment, for each line of content in the code file to be tested, in response to determining that the line exists in a character matching the language to be recognized that is not a character of the annotation type in step 404, the electronic device may record at least one of the following information of the character matching the language to be recognized: the matched characters matched with the language to be recognized, the file name and the path of the file where the matched characters are located, and the line number where the matched characters are located. And the electronic equipment executes step 406 after matching the content of the code file to be detected and matching the characters matched with the language to be recognized.
And 406, generating a test report when the content of the code file to be tested is matched and the characters matched with the language to be recognized are matched.
In this embodiment, when the electronic device finishes matching the content of the code file to be tested and matches a character matching the language to be recognized, the electronic device may acquire record information of the character matching the language to be recognized, and generate a test report after processing the acquired record information. By way of example, the electronic device may integrate the acquired recording information to generate a test report of a text document type, and store the test report to a specified path for a user to view.
As can be seen from fig. 4, compared with the embodiment corresponding to fig. 2, the flow 400 of the testing method in this embodiment highlights the step of determining the annotation type character. Therefore, the scheme described in the embodiment can not record the information of the annotation type characters, and can shorten the test time, reduce the test missing rate and effectively improve the test efficiency.
With further reference to fig. 5, as an implementation of the method shown in the above figures, the present application provides an embodiment of a testing apparatus, which corresponds to the embodiment of the method shown in fig. 2, and which can be applied to various electronic devices.
As shown in fig. 5, the testing apparatus 500 of the present embodiment includes: an acquisition unit 501, a selection unit 502, a matching unit 503 and a generation 504. The obtaining unit 501 is configured to obtain a code file path, a code file type, and a language to be recognized; the selecting unit 502 is configured to search each code file under the code file path, and select a code file with a file type the same as that of the code file as a code file to be tested; the matching unit 503 is configured to read the content of the code file to be identified, and match the characters matched with the language to be identified in the content of the code file to be identified by using a regular expression; and the generating unit 504 is configured to generate a test report in response to matching a character matching the language to be recognized.
In this embodiment, the obtaining unit 501 of the testing apparatus 500 may obtain the code file path, the code file type, and the language to be recognized configured by the user without network connection. As an example, the obtaining unit 501 may provide an interface for a user to input a code file path, a code file type, and a language to be recognized on the interface, and after the user inputs and submits the content, the obtaining unit 501 may obtain the code file path, the code file type, and the language to be recognized, which are input by the user.
In this embodiment, based on the code file path, the code file type, and the language to be recognized that are acquired by the acquisition unit 501, the selection unit 502 may recursively traverse all the code files in the code file path, and select a code file having a file type that is the same as the code file type as the code file to be recognized.
In this embodiment, based on the code file to be tested determined by the selecting unit 502, the matching unit 503 may read the content of the code file to be tested, and may match characters matching the language to be recognized in the content of the code file to be tested by using a regular expression.
In this embodiment, in response to the matching unit 503 matching out the character matching the language to be recognized, the generating unit 504 may acquire the record information of the character matching the language to be recognized, and generate the test report after processing the acquired record information. As an example, the generating unit 504 may integrate the acquired recording information to generate a test report of a text document type, and store the test report to a specified path for the user to view.
In some optional implementations of this embodiment, the matching unit 503 includes: a matching subunit (not shown in fig. 1), configured to match, by using a regular expression, the content of each line of the code file to be identified, determine whether a character matching the language to be identified exists in the line, and if so, record at least one of the following items: the method comprises the following steps of identifying the language to be identified, identifying the file name and the path of the file where the character matched with the language to be identified is located, and identifying the line number where the character matched with the language to be identified is located.
In some optional implementations of this embodiment, the matching unit 503 includes: a determining subunit (not shown in fig. 1), configured to match the content of each line of the code file to be detected by using a regular expression, determine whether the line has characters matching the language to be recognized, and if so, further determine whether the characters matching the language to be recognized are characters of an annotation type; a first processing subunit (not shown in fig. 1) configured for, in response to determining that the character matching the language to be recognized is not a character of the annotation type, recording at least one of: the language identification method comprises the following steps of identifying the language to be identified, identifying the character matched with the language to be identified, identifying the file name and the path of the file where the character matched with the language to be identified is located, and identifying the line number where the character matched with the language to be identified is located.
In some optional implementations of this embodiment, the matching unit 503 includes: a second processing subunit (not shown in fig. 1) configured to, in response to determining that the character matching the language to be recognized is a character of the annotation type, continue reading the content of the code file to be recognized.
In some optional implementations of the present embodiment, the testing apparatus 500 further includes: and a conversion unit (not shown in fig. 1) configured to determine whether the encoding mode of the code file to be tested is unicode encoding, and if not, convert the encoding mode of the code file to be tested into unicode encoding.
In some optional implementations of this embodiment, the code file path is a path of a distributed version control system or a local code folder path.
In some optional implementations of the present embodiment, the testing apparatus 500 further includes: a path determining unit (not shown in fig. 1) configured to determine whether the path of the code file is a path of a distributed version control system, and if so, download the code file to the local from a server indicated by the path of the distributed version control system; and a replacing unit (not shown in fig. 1) configured to replace the acquired path of the distributed version control system with the downloaded code file at the local path.
In some optional implementations of the present embodiment, the content of the test report includes at least one of: the matched characters matched with the language to be recognized, the file name and the path of the file where the matched characters are located, and the number of lines where the matched characters are located.
Referring now to FIG. 6, shown is a block diagram of a computer system 600 suitable for use in implementing a terminal device of an embodiment of the present application.
As shown in fig. 6, the computer system 600 includes a Central Processing Unit (CPU)601 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage section 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data necessary for the operation of the system 600 are also stored. The CPU 601, ROM 602, and RAM 603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
The following components are connected to the I/O interface 605: an input portion 606 including a keyboard, a mouse, and the like; an output portion 607 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 608 including a hard disk and the like; and a communication section 609 including a network interface card such as a LAN card, a modem, or the like. The communication section 609 performs communication processing via a network such as the internet. The driver 610 is also connected to the I/O interface 605 as needed. A removable medium 611 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 610 as necessary, so that a computer program read out therefrom is mounted in the storage section 608 as necessary.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program tangibly embodied on a machine-readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 609, and/or installed from the removable medium 611. The computer program performs the above-described functions defined in the method of the present application when executed by a Central Processing Unit (CPU) 601.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present application may be implemented by software or hardware. The described units may also be provided in a processor, and may be described as: a processor includes an acquisition unit, a selection unit, a matching unit, and a generation unit. Where the names of these units do not in some cases constitute a limitation of the unit itself, for example, the acquisition unit may also be described as a "unit to acquire a code file path, a code file type, and a language to be recognized".
As another aspect, the present application also provides a non-volatile computer storage medium, which may be the non-volatile computer storage medium included in the apparatus in the above-described embodiments; or it may be a non-volatile computer storage medium that exists separately and is not incorporated into the terminal. The non-transitory computer storage medium stores one or more programs that, when executed by a device, cause the device to: acquiring a code file path, a code file type and a language to be identified; searching each code file under the code file path, and selecting a code file with the same file type as the code file to be detected; reading the content of the code file to be identified, and matching characters matched with the language to be identified in the content of the code file to be identified by using a regular expression; and generating a test report in response to matching the characters which are matched with the language to be recognized.
The above description is only a preferred embodiment of the application and is illustrative of the principles of the technology employed. It will be appreciated by a person skilled in the art that the scope of the invention as referred to in the present application is not limited to the embodiments with a specific combination of the above-mentioned features, but also covers other embodiments with any combination of the above-mentioned features or their equivalents without departing from the inventive concept. For example, the above features may be replaced with (but not limited to) features having similar functions disclosed in the present application.

Claims (18)

1. A method of testing, the method comprising:
acquiring a code file path, a code file type and a language to be identified;
searching each code file under the code file path, selecting a code file with the same file type as the code file to be tested, and generating a file set for storing the file name and the path of the code file to be tested;
reading the content of the code file to be identified, and matching characters matched with the language to be identified in the content of the code file to be identified by using a regular expression;
generating a test report in response to matching the characters matched with the language to be recognized;
the reading the content of the code file to be identified, and matching the characters matched with the language to be identified in the content of the code file to be identified by using a regular expression, includes:
determining whether the file set is empty, reading information of a code file to be tested from the file set in response to the fact that the file set is not empty, and taking out the code file to be tested according to the information of the code file to be tested;
determining whether the coding mode of the code file to be tested is uniform code coding, if not, converting the coding mode of the code file to be tested into uniform code coding, and then reading the content of the code file to be tested, and if the coding mode of the code file to be tested is uniform code coding, reading the content of the code file to be tested;
matching characters matched with the language to be recognized in the content of the code file to be detected by using a regular expression;
and after all the characters in the code file to be tested are matched, deleting the information of the code file to be tested from the file set.
2. The method according to claim 1, wherein the reading the content of the code file to be identified, and matching the characters matching the language to be identified in the content of the code file to be identified by using a regular expression comprises:
matching the content of each line of the code file to be detected by using a regular expression, determining whether the line has characters matched with the language to be recognized, and if so, recording at least one of the following items: the characters matched with the language to be recognized, the file name and the path of the file where the characters matched with the language to be recognized are located, and the line number of the line where the characters matched with the language to be recognized are located.
3. The method according to claim 1, wherein the reading the content of the code file to be identified, and matching the characters matching the language to be identified in the content of the code file to be identified by using a regular expression comprises:
matching the content of each line of the code file to be detected by using a regular expression, determining whether the line has characters matched with the language to be recognized, and if so, further determining whether the characters matched with the language to be recognized are the characters of the annotation type;
in response to determining that the character matching the language to be recognized is not a character of the annotation type, recording at least one of: the characters matched with the language to be recognized, the file name and the path of the file where the characters matched with the language to be recognized are located, and the line number of the line where the characters matched with the language to be recognized are located.
4. The method according to claim 3, wherein the reading the content of the code file to be identified, and matching the characters matching the language to be identified in the content of the code file to be identified by using a regular expression comprises:
and in response to determining that the characters matched with the language to be recognized are the characters of the annotation type, continuing to read the content of the code file to be recognized.
5. The method according to claim 1, wherein before reading the content of the code file to be recognized and matching the characters matching the language to be recognized in the content of the code file to be recognized by using a regular expression, the method further comprises:
and determining whether the coding mode of the code file to be tested is uniform code coding, and if not, converting the coding mode of the code file to be tested into uniform code coding.
6. The method of claim 1, wherein the code file path is a path of a distributed version control system or a local code folder path.
7. The method according to claim 6, wherein before searching for each code file in the code file path and selecting a code file with a file type same as that of the code file as a code file to be tested, the method further comprises:
determining whether the path of the code file is the path of the distributed version control system, if so, downloading the code file to the local from a server indicated by the path of the distributed version control system;
and replacing the acquired path of the distributed version control system by the path of the downloaded code file at the local.
8. The method according to one of claims 1 to 7, characterized in that the content of the test report comprises at least one of the following: the method comprises the steps of matching out characters matched with the language to be recognized, the file name and the path of a file where the matched characters matched with the language to be recognized are located, and the line number of lines where the matched characters matched with the language to be recognized are located.
9. A test apparatus, the apparatus comprising:
the system comprises an acquisition unit, a recognition unit and a recognition unit, wherein the acquisition unit is configured to acquire a code file path, a code file type and a language to be recognized;
the selecting unit is configured to search each code file under the code file path, select a code file with the same file type as the code file to be tested, and generate a file set for storing the file name and the path of the code file to be tested;
the matching unit is configured to read the content of the code file to be identified and match characters matched with the language to be identified in the content of the code file to be identified by using a regular expression;
the generating unit is configured to respond to the matched characters with the language to be recognized and generate a test report;
the matching unit is further configured to determine whether the file set is empty, read information of a code file to be tested from the file set in response to the file set not being empty, and extract the code file to be tested according to the information of the code file to be tested; determining whether the coding mode of the code file to be tested is uniform code coding, if not, converting the coding mode of the code file to be tested into uniform code coding, and then reading the content of the code file to be tested, and if the coding mode of the code file to be tested is uniform code coding, reading the content of the code file to be tested; matching characters matched with the language to be recognized in the content of the code file to be detected by using a regular expression; and after all the characters in the code file to be tested are matched, deleting the information of the code file to be tested from the file set.
10. The apparatus of claim 9, wherein the matching unit comprises:
the matching subunit is configured to match the content of each line of the code file to be identified by using a regular expression, determine whether the line has characters matched with the language to be identified, and if so, record at least one of the following items: the characters matched with the language to be recognized, the file name and the path of the file where the characters matched with the language to be recognized are located, and the line number of the line where the characters matched with the language to be recognized are located.
11. The apparatus of claim 9, wherein the matching unit comprises:
the determining subunit is configured to match the content of each line of the code file to be detected by using a regular expression, determine whether the line has characters matched with the language to be recognized, and if so, further determine whether the characters matched with the language to be recognized are characters of an annotation type;
a first processing subunit configured to, in response to determining that the character matching the language to be recognized is not a character of an annotation type, record at least one of: the characters matched with the language to be recognized, the file name and the path of the file where the characters matched with the language to be recognized are located, and the line number of the line where the characters matched with the language to be recognized are located.
12. The apparatus of claim 11, wherein the matching unit comprises:
and the second processing subunit is configured to, in response to determining that the character matched with the language to be recognized is a character of an annotation type, continue to read the content of the code file to be detected.
13. The apparatus of claim 9, further comprising:
and the conversion unit is configured to determine whether the coding mode of the code file to be tested is uniform code coding, and if not, convert the coding mode of the code file to be tested into uniform code coding.
14. The apparatus of claim 9, wherein the code file path is a path of a distributed version control system or a local code folder path.
15. The apparatus of claim 14, further comprising:
the path determining unit is configured to determine whether the code file path is a path of the distributed version control system, and if so, download the code file to the local from a server indicated by the path of the distributed version control system;
and the replacing unit is configured for replacing the acquired path of the distributed version control system by the downloaded code file at the local path.
16. The apparatus according to one of claims 9-15, wherein the content of the test report comprises at least one of: the method comprises the steps of matching out characters matched with the language to be recognized, the file name and the path of a file where the matched characters matched with the language to be recognized are located, and the line number of lines where the matched characters matched with the language to be recognized are located.
17. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-8.
18. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-8.
CN201610643110.9A 2016-08-08 2016-08-08 Test method and device Active CN107704374B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610643110.9A CN107704374B (en) 2016-08-08 2016-08-08 Test method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610643110.9A CN107704374B (en) 2016-08-08 2016-08-08 Test method and device

Publications (2)

Publication Number Publication Date
CN107704374A CN107704374A (en) 2018-02-16
CN107704374B true CN107704374B (en) 2021-05-25

Family

ID=61169298

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610643110.9A Active CN107704374B (en) 2016-08-08 2016-08-08 Test method and device

Country Status (1)

Country Link
CN (1) CN107704374B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1395171A (en) * 2001-07-06 2003-02-05 华为技术有限公司 Code statistical tool of computer software program and its implementing method
CN102929596A (en) * 2012-09-21 2013-02-13 华为技术有限公司 Code checking method and device
CN104699263A (en) * 2015-03-18 2015-06-10 北京交通大学 Symbol string acquiring method and device
US9361337B1 (en) * 2011-10-05 2016-06-07 Cumucus Systems Incorporated System for organizing and fast searching of massive amounts of data

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1395171A (en) * 2001-07-06 2003-02-05 华为技术有限公司 Code statistical tool of computer software program and its implementing method
US9361337B1 (en) * 2011-10-05 2016-06-07 Cumucus Systems Incorporated System for organizing and fast searching of massive amounts of data
CN102929596A (en) * 2012-09-21 2013-02-13 华为技术有限公司 Code checking method and device
CN104699263A (en) * 2015-03-18 2015-06-10 北京交通大学 Symbol string acquiring method and device

Also Published As

Publication number Publication date
CN107704374A (en) 2018-02-16

Similar Documents

Publication Publication Date Title
CN111367595B (en) Data processing method, program running method, device and processing equipment
CN111279335B (en) Retrieving multilingual documents based on document structure extraction
CN108711443B (en) Text data analysis method and device for electronic medical record
US20200250208A1 (en) Automatic Discovery of Locations of Translated Text in Localized Applications
CN112015430A (en) JavaScript code translation method and device, computer equipment and storage medium
CN111176996A (en) Test case generation method and device, computer equipment and storage medium
US20150161160A1 (en) Application Localization
US20040148591A1 (en) Method, apparatus, and program for automated application context delivery to translators
CN113419721B (en) Web-based expression editing method, device, equipment and storage medium
CN111144210A (en) Image structuring processing method and device, storage medium and electronic equipment
JPWO2017141893A1 (en) Software analysis apparatus and software analysis method
CN107239209B (en) Photographing search method, device, terminal and storage medium
CN104750604A (en) Generating method and device for browser compatibility test case
CN107704374B (en) Test method and device
US11947530B2 (en) Methods and systems to automatically generate search queries from software documents to validate software component search engines
CN110083576B (en) Cache directory identification method and device
CN112699642B (en) Index extraction method and device for complex medical texts, medium and electronic equipment
CN113177421A (en) Method, device, equipment and storage medium for quality inspection of translation document
US20150324333A1 (en) Systems and methods for automatically generating hyperlinks
CN112836477B (en) Method and device for generating code annotation document, electronic equipment and storage medium
CN112035373B (en) Method, device, server and medium for testing basic test script
CN113505570B (en) Reference is made to empty checking method, device, equipment and storage medium
US20240013528A1 (en) Platform detection algorithm for forensic images
KR102286451B1 (en) Method for recognizing obfuscated identifiers based on natural language processing, recording medium and device for performing the method
CN110737757B (en) Method and apparatus for generating information

Legal Events

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