CN109308260A - A kind of method and terminal of automatically generating unit test code - Google Patents

A kind of method and terminal of automatically generating unit test code Download PDF

Info

Publication number
CN109308260A
CN109308260A CN201811004196.6A CN201811004196A CN109308260A CN 109308260 A CN109308260 A CN 109308260A CN 201811004196 A CN201811004196 A CN 201811004196A CN 109308260 A CN109308260 A CN 109308260A
Authority
CN
China
Prior art keywords
relied
class
input
generating unit
automatically generating
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.)
Granted
Application number
CN201811004196.6A
Other languages
Chinese (zh)
Other versions
CN109308260B (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.)
Fujian Tianquan Educational Technology Ltd
Original Assignee
Fujian Tianquan Educational Technology 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 Fujian Tianquan Educational Technology Ltd filed Critical Fujian Tianquan Educational Technology Ltd
Priority to CN201811004196.6A priority Critical patent/CN109308260B/en
Publication of CN109308260A publication Critical patent/CN109308260A/en
Application granted granted Critical
Publication of CN109308260B publication Critical patent/CN109308260B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

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
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention discloses the methods and terminal of a kind of automatically generating unit test code, the specified input and output of to-be-measured cell are directed to by receiving, the analysis input and output obtain all branches that may be present, the input and output of each branch are analyzed again, judge whether to need to drive piles, piling if necessary, based on all branches, generation unit tests code, automatically generating unit test code may be implemented, reduce cumbersome duplicate work, also can be used in the maintenance in later period, the time is saved, is improved work efficiency.

Description

A kind of method and terminal of automatically generating unit test code
Technical field
The present invention relates to software testing technology fields, a kind of method more particularly, to automatically generating unit test code and Terminal.
Background technique
Unit testing is that developer writes a bit of code, for examine tested code a very little, it is very specific Whether function is correct.Typically, a unit testing is for judging some specific function under some specified conditions or scene Behavior.Unit testing is the function of code and robustness is most basic, most important means, is very heavy in entire soft project The link wanted.
But r/w cell test is cumbersome and time-consuming, if there is the judgement sentence being made of 3 conditions in a method, that To realize its complete branch's covering (so-called branch's covering, refer to that the code of unit testing will go around all branches), Developer needs to write 23=8 test cases, the branch of one section of program is more, to realize that branch covers written test case To be increased with exponential form, due to the overwhelming majority code be it is identical, only input parameter it is different, test case also will be Similar, there is no technology contents, and the code of unit testing is not to be once and for all, with the change of software code More, the code of unit testing will also update therewith, i.e., constantly to go to safeguard these unit testing codes, this will spend more Time.
Other than time cost, unit testing also needs learning cost, and a tester writes to expertly grasp The skill of unit testing code is the study for needing to carry out system.Tester specifies certain conditions, it is expected that some method or Function obtains specific as a result, and a method or function are possible to other method letters under the collective effect of these conditions Number has dependence, but system can only run that tested code block, other any methods when unit testing Perhaps function is not carried out this tester is just needed to go to simulate the method or function that these are relied on, allow they Still specified value can be returned in the case where not being performed, this behavior is referred to as piling (mock), energy in unit testing It cannot drive piles, whether correct drive piles, determine the effect of unit testing.
To sum up, unit testing is very important, but under traditional unit testing frame, it is programmers again Be reluctant to write, unit testing needs tester to learn third-party testing frame, write a large amount of duplicated code and constantly into Row maintenance, it is also necessary to which tester grasps the technology of piling, time-consuming and laborious.
Summary of the invention
The technical problems to be solved by the present invention are: the method and terminal of a kind of automatically generating unit test code are provided, It can be realized automatically generating unit test code, reduce cumbersome duplicate work, save the time, improve efficiency.
In order to solve the above-mentioned technical problem, a kind of technical solution that the present invention uses are as follows:
A kind of method of automatically generating unit test code, comprising steps of
S1, the specified input and output for being directed to to-be-measured cell are received;
Input and output described in S2, analysis obtain all branches that may be present;
S3, the input and output for analyzing each branch judge whether to need to drive piles, and drive piles if necessary;
S4, all branches are based on, generation unit tests code.
In order to solve the above-mentioned technical problem, the another technical solution that the present invention uses are as follows:
A kind of terminal of automatically generating unit test code, including memory, processor and storage are on a memory and can The computer program run on the processor, the processor perform the steps of when executing the computer program
S1, the specified input and output for being directed to to-be-measured cell are received;
Input and output described in S2, analysis obtain all branches that may be present;
S3, the input and output for analyzing each branch judge whether to need to drive piles, and drive piles if necessary;
S4, all branches are based on, generation unit tests code.
The beneficial effects of the present invention are: by receiving the input and output specified for to-be-measured cell, analyze described defeated Enter output and obtain all branches that may be present, then analyze the input and output of each branch, judges whether to need to drive piles, if It needs, drives piles, be based on all branches, generation unit tests code, and automatically generating unit test code may be implemented, and reduces numerous Trivial duplicate work, also can be used in the maintenance in later period, saves the time, improves work efficiency.
Detailed description of the invention
Fig. 1 is a kind of flow chart of the method for automatically generating unit test code of inventive embodiments;
Fig. 2 is a kind of terminal structure schematic diagram of automatically generating unit test code of the embodiment of the present invention;
Label declaration:
1, the terminal of automatically generating unit test code;2, memory;3, processor.
Specific embodiment
To explain the technical content, the achieved purpose and the effect of the present invention in detail, below in conjunction with embodiment and cooperate attached Figure is explained.
The most critical design of the present invention is: being analyzed to obtain after receiving the specified input and output for to-be-measured cell All branches that may be present;The input and output for analyzing each branch judge whether to need to drive piles, and drive piles if necessary; Based on all branches, generation unit tests code, realizes automatically generating for unit testing code.
Please refer to Fig. 1, a kind of method of automatically generating unit test code, comprising steps of
S1, the specified input and output for being directed to to-be-measured cell are received;
Input and output described in S2, analysis obtain all branches that may be present;
S3, the input and output for analyzing each branch judge whether to need to drive piles, and drive piles if necessary;
S4, all branches are based on, generation unit tests code.
As can be seen from the above description, the beneficial effects of the present invention are: the specified input of to-be-measured cell is directed to by receiving Output analyzes the input and output and obtains all branches that may be present, then analyzes the input and output of each branch, judges Whether need to drive piles, drive piles if necessary, be based on all branches, generation unit tests code, may be implemented to automatically generate list Member test code, reduces cumbersome duplicate work, also can be used in the maintenance in later period, save the time, improves work effect Rate.
Further, judge whether that needing to drive piles includes: all output result character strings of traversal described in step S3, to institute It states character string and successively carries out semantic analysis;Judge that the character string is the return value of a determining value or a method, if It is that determining value does not need then to drive piles, if it is the return value of a method, then needs to drive piles.
Seen from the above description, it carries out semantic analysis to judge whether to need to drive piles automatically output result character string, subtracts The light workload of related personnel, improves testing efficiency.
Further, it drives piles described in step S3 and includes:
S31, by way of succession, a subclass of class where obtaining being relied on method;
The method being relied on described in S32, rewriting makes the method that is relied on of one subclass return to designated value.
Seen from the above description, designated value is returned to by rewriteeing the method being relied in the subclass of succession automatically, mentioned The high efficiency of piling, facilitates the further implementation of test.
Further, it is also wrapped before the subclass for obtaining class where being relied on method described later in the step S31 Include: whether the class where being relied on method described in judgement is the class or final method that can not be inherited the final rewritten, If so, be relied on the bytecode of class where method described in modification, by it is described be relied on method where class become non-final Class or method.
Seen from the above description, by judge automatically it is described be relied on method where class whether be one and can not be inherited The class or final method of the final of rewriting is improved and is beaten if can be then revised as the class or method of non-final automatically The efficiency of stake mitigates many cumbersome work for related personnel, has saved the time.
Further, the step S1 further include: judge whether to need to modify input, be directed to list to be measured if so, receiving The specified modified input of member.
Seen from the above description, specified input need to be only modified when to-be-measured cell changes, does not need to rewrite for test Code, so that it may all test case codes are regenerated, it is convenient and efficient, many cumbersome duplicate work of people are eliminated, It improves work efficiency.
Referring to figure 2., a kind of terminal 1 of automatically generating unit test code, including memory 2, processor 3 and be stored in On memory 2 and the computer program that can be run on the processor 3, when the processor 3 executes the computer program It performs the steps of
S1, the specified input and output for being directed to to-be-measured cell are received;
Input and output described in S2, analysis obtain all branches that may be present;
S3, the input and output for analyzing each branch judge whether to need to drive piles, and drive piles if necessary;
S4, all branches are based on, generation unit tests code.
As can be seen from the above description, the beneficial effects of the present invention are: the specified input of to-be-measured cell is directed to by receiving Output analyzes the input and output and obtains all branches that may be present, then analyzes the input and output of each branch, judges Whether need to drive piles, drive piles if necessary, be based on all branches, generation unit tests code, may be implemented to automatically generate list Member test code, reduces cumbersome duplicate work, saves the time, improve work efficiency.
Further, judge whether that needing to drive piles includes: all output result character strings of traversal described in step S3, to institute It states character string and successively carries out semantic analysis;Judge that the character string is the return value of a determining value or a method, if It is that determining value does not need then to drive piles, if it is the return value of a method, then needs to drive piles.
Seen from the above description, it carries out semantic analysis to judge whether to need to drive piles automatically output result character string, subtracts The light workload of related personnel, improves testing efficiency.
Further, it drives piles described in step S3 and includes:
S31, by way of succession, a subclass of class where obtaining being relied on method;
The method being relied on described in S32, rewriting makes the method that is relied on of one subclass return to designated value.
Seen from the above description, designated value is returned to by rewriteeing the method being relied in the subclass of succession automatically, mentioned The high efficiency of piling, facilitates the further implementation of test.
Further, it is also wrapped before the subclass for obtaining class where being relied on method described later in the step S31 Include: whether the class where being relied on method described in judgement is the class or final method that can not be inherited the final rewritten, If so, be relied on the bytecode of class where method described in modification, by it is described be relied on method where class become non-final Class or method.
Seen from the above description, by judge automatically it is described be relied on method where class whether be one and can not be inherited The class or final method of the final of rewriting is improved and is beaten if can be then revised as the class or method of non-final automatically The efficiency of stake mitigates many cumbersome work for related personnel, has saved the time.
Further, the step S1 further include: judge whether to need to modify input, be directed to list to be measured if so, receiving The specified modified input of member.
Seen from the above description, specified input need to be only modified when to-be-measured cell changes, does not need to rewrite for test Code, so that it may all test case codes are regenerated, it is convenient and efficient, many cumbersome duplicate work of people are eliminated, It improves work efficiency.
Embodiment one
Please refer to Fig. 1, a kind of method of automatically generating unit test, comprising steps of
S1, the specified input and output for being directed to to-be-measured cell are received;
Wherein, the input refers to the condition of if sentence in code, and the output refers to when condition meets or not It is when meeting for example to become four parameters by three parameters as a result, if the source code of the to-be-measured cell is changed, it is passing Need to write 16 test cases again under system way, and the present invention only needs to modify the condition of input, can regenerate automatically Test case;
Input and output described in S2, analysis obtain all branches that may be present;
S3, the input and output for analyzing each branch judge whether to need to drive piles, and drive piles if necessary;
Specifically, successively carrying out semantic analysis to the character string by traversing all output result character strings;Judgement should Character string is the return value of a determining value or a method, does not need then to drive piles if it is determining value, if it is one The return value of a method then needs to drive piles;
When piling, whether the class where being first relied on method described in judgement, which is one, to be inherited the final rewritten Class or final method, if so, the bytecode for the class being relied on where method described in modification, is relied on described where method Class become the class or method of non-final;
Then by way of succession, a subclass of class where being relied on method is obtained;The side being relied on described in rewriting Method makes the method that is relied on of one subclass return to designated value;
S4, all branches are based on, generation unit tests code.
Specifically, being every by the test case that the designated value write-in for determining value or piling return is met to input condition One branch generates test case code, to complete unit testing.
Embodiment two
Method described in embodiment one is applied to specific example, in the test of java:
Firstly, system provides following method for inputting parameter:
A) method of condition, (hereinafter referred to as if method) is arranged in, this method is used to receive the condition language of developer's offer Sentence, it is assumed that have such a sentence: a > 0 return? 1:0, condition are exactly " a > 0 ";
B) method (hereinafter referred to as then method) of return value when condition meets is arranged in, this method is opened for receiving In the if method that originator provides to condition obtain meeting when value, be exactly " 1 " for the above predicate sentence;
C) method (hereinafter referred to as else method) of return value when condition is unsatisfactory for is arranged in, this method is for receiving In the if method that developer provides to condition it is unmet when value, be exactly " 0 " for the above predicate sentence;
D) method (hereinafter referred to as verify method) that some method under specified requirements is performed number, this side is arranged in Method be used to receive in the if method of developer's offer to condition meet or when being unsatisfactory for, the number that some sentence executes, because As soon as a method is possible to no return value, to need when then testing such method by confirming certain in java Whether a method is executed to carry out, and the sentence of this method input, which is referred to as, confirms sentence;
E) exports use-case method, hereinafter referred to as build method, and developer can be obtained all tests by the method and be used The code of example;
Then system realizes automatically generating for unit testing code by following steps:
S1, the specified input and output for being directed to to-be-measured cell are received, specifically:
(1) system receives developer and calls if method, the input condition of setting;
(2) developer calls then method, equally in the form of character string that method to be measured is signified in meeting step (1) The result obtained under conditions of fixed is supplied to system;
(3) developer calls verify method (if the need arises), method to be measured equally in the form of character string The method and number needed to be implemented under conditions of meeting specified in step 2 is supplied to system;
(4) developer calls else method (if necessary), method to be measured not equally in the form of character string Meet step 2 it is inner it is specified under conditions of obtained result be supplied to system;
(5) developer calls verify method (if the need arises), method to be measured equally in the form of character string The method and number needed to be implemented under conditions of being unsatisfactory for specified in step 2 is supplied to system;
(6) all inputs of developer will be all temporarily stored in memory;
(7) developer repeats (2)-(6) step, has all specified until all input and output that may be present of method to be measured At;
Wherein, when unit input condition to be tested needs to change, then the specified modification for being directed to to-be-measured cell is received The condition of if method is modified in input afterwards;
Input and output described in S2, analysis obtain all branches that may be present, specifically:
(1) instruction for the execution build method that developer sends is received;
(2) after the build that system receives developer's sending is instructed, all input condition character strings can be traversed, successively Semantic analysis is carried out, judges that the input of this method there are several conditions, these conditions are combined in what manner, these How many branch is determined the how many a test cases of generation, for example some condition is " a > 0&&b > 0 " by the combination of part, that System by analysis, finds the compound condition that this condition is made of two conditions, will then generate 4 tests and use Example;
S3, the input and output for analyzing each branch judge whether to need to drive piles, and drive piles if necessary:
Specifically, system traverses all output result character strings, semantic analysis is successively carried out, judges that the character string is one The return value of determining value or a method, if it is determining value then can above-mentioned qualified test case this is written Value, can then drive piles to this method if it is the return value of a method.I.e. before the operation of tested code, system can lead to The mode for crossing the bytecode of modification class, the above-mentioned return value for being relied on method is modified, the return value for the method that is relied on It is revised as a preassigned random value.In this way, this method being relied on will return when running test case Good specified value, and the actual code logic for being relied on method will not be run, and ensure that the pure of tested method Property;
S4, all branches being based on, generation unit tests code, specifically:
For each branch, corresponding test case code is generated, system exports the test case of above-mentioned all branches Code to engineering catalogue under src/test/java/ be tested class same paths catalogue, all test case codes i.e. constitute For the test of the unit;
Finally, developer enters the catalogue, running unit test case is the test realized to the unit.
By above step, as long as developer can be in the case where minute quantity inputs --- actually source code is carried out Duplication is pasted, so that it may several complete test case codes of the full branch's covering of tested method is obtained, when saving a large amount of Between.And developer hardly needs and learns new content: this programme only has a few method, with any one third party Unit testing frame is compared, and can be ignored.In the maintenance in later period, the same available new test case of method Which place code has need to modify, can equally save a large amount of time without taking a lot of trouble to search in original use-case.
Embodiment three
Method described in embodiment two is applied to specific example, in the test of java:
Assuming that developer will be to following this section of code r/w cell test case:
public class Foo{
public int getValue(int value1,int value2,int value3){
if(value1>0||value2>0||value3>0){
return MathTools.next(value1,value2,value3);
}
return 0;
}
}
The core of this section of code only has three rows, as a result, returning when three parameters of input are all natural number The return value (MathTools.next) of some method of another class, is otherwise returned to 0;To guarantee that full branch's covering will be write 8 test cases, in addition later maintenance needs take a significant amount of time, using the present invention program, process is as follows:
S1, the specified input and output for being directed to to-be-measured cell are received, specifically:
(1) firstly, developer calls if method, input condition " value1 > 0 | | value2 > 0 | | value3 > 0 ", i.e. source Character string in code as if sentence condition;
(2) system receive input, by condition " value1 > 0 | | value2 > 0 | | value3 > 0 " deposit array;
(3) then developer calls then method, is arranged " MathTools.next (value1, value2, value3) ", It is equally the character string in source code, and system receives output result when meeting above-mentioned condition;
(4) developer calls verify (" MathTools.next (value1, value2, value3) ", 1) method, if Set condition " value1 > 0 | | value2 > 0 | | value3 > 0 " obtain satisfaction in the case where, " MathTools.next This method of (value1, value2, value3) " has been performed once.
(5) developer calls else method, if reset, system receives output result when being unsatisfactory for above-mentioned condition;
(6) developer calls verify (" MathTools.next (value1, value2, value3) ", 0) method, if Set condition " value1 > 0 | | value2 > 0 | | value3 > 0 " it is unmet in the case where, " MathTools.next This method of (value1, value2, value3) " will not be performed;
Input and output described in S2, analysis obtain all branches that may be present, specifically:
(1) developer calls build method, notice construction test case code;
(2) system starts to analyze the data in memory, is conditional statement first, in this implementation after receiving build instruction Only one conditional statement in example, i.e., " value1 > 0 | | value2 > 0 | | value3 > 0 ", this is a compound condition, it will quilt Split into three conditions, be respectively: value1 > 0, value2 > 0, vlaue3 > 0, three conditions will have 8 kinds of combinations, therefore system 8 test cases will be generated;
(3) system continuation analysis condition sentence, judgement only value1≤0 and value2≤0 and value3≤0 In the case of, which is not being met, and other 7 kinds of combinations can meet this condition, then will be in 8 surveys of generation In example on probation, enabling the return value for 7 use-cases for meeting condition is " MathTools.next (value1, value2, value3) ", The return value for being unsatisfactory for the use-case of condition is 0;
S3, the input and output for analyzing each branch judge whether to need to drive piles, and drive piles if necessary, specifically:
(1) network analysis output statement, current method is there are two output, and one is " 0 ", the other is character string " MathTools.next (value1, value2, value3) ", system judge that " 0 " is an integer value, directly give;But MathTools.next (value1, value2, value3) is the return value of some method of another class, is beaten Stake is rewritten in subclass in a manner of succession and is relied on method, provides a return value;
(2) network analysis confirms sentence, and discovery is in the case where condition meets, method " MathTools.next (value1, value2, value3) " can be performed 1 time, otherwise executed 0 time, i.e., be not performed;
S4, all branches being based on, generation unit tests code, specifically:
(1) after all inputs, output statement analysis, system is assigned according to the input condition of each test case Value provides the random value for meeting or being unsatisfactory for condition, generate assignment code;According to whether piling, is beaten Stake;Generate the code for calling tested method;Generate the code of judgement output;Generate confirmation statement code;Finally by above-mentioned code Merge, output is at a complete test case code to specified catalogue;
(2) above-mentioned tested method will eventually generate following 8 test cases, these use-cases are all that can directly run simultaneously Testing result, code is as follows:
Test case one:
Test case two:
Test case three:
Test case four:
Test case five:
Test case six:
Test case seven:
Test case eight:
If the source code of above-mentioned tested method is changed, for example becomes four parameters by three parameters, then passing Developer under system way needs to write 16 test cases again, and only needs to modify using the developer of this system The parameter of if method is passed to new conditional statement, then executes build method, can regenerate test case;
@Prepare { MathTools.class }, MockUtils.mockStatic in above example code (MathTools.class), MockUtils.when (...) .thenReturn (...), MockUtils.verify etc. be It is the content of third square bearer, needs related personnel to learn when tradition implements test, and does not need to learn in the present invention It practises and how to go to drive piles, in this embodiment it is not even necessary to know that cries piling, it is only necessary to tell what this system will do, other all things It will all be completed by system, briefly, in the present embodiment, developer can complete tens rows up to a hundred only with 4 line codes Unit testing code.
Example IV
A kind of terminal 1 of automatically generating unit test code, including memory 2, processor 3 and be stored on memory 2 And the computer program that can be run on the processor 3, the processor 3 realize embodiment when executing the computer program Each step in one.
In conclusion the method and terminal of a kind of automatically generating unit test code provided by the invention, by receiving needle Specified input and output to to-be-measured cell analyze the input and output and obtain all branches that may be present, then analyze every The input and output of one branch judge whether to need to drive piles, and drive piles if necessary, are based on all branches, generation unit test Automatically generating unit test code may be implemented in code, reduces cumbersome duplicate work, can also make in the maintenance in later period With saving the time, improve work efficiency, correspond to automatic by semantic analysis to determine whether needing to drive piles and automatic Piling, improves the efficiency of piling, further improves testing efficiency, only need to modify input i.e. when testing different to-be-measured cells Unit testing code can be regenerated, it is simple and convenient, it is easily operated, it brings great convenience.
The above description is only an embodiment of the present invention, is not intended to limit the scope of the invention, all to utilize this hair Equivalents made by bright specification and accompanying drawing content are applied directly or indirectly in relevant technical field, similarly include In scope of patent protection of the invention.

Claims (10)

1. a kind of method of automatically generating unit test code, which is characterized in that comprising steps of
S1, the specified input and output for being directed to to-be-measured cell are received;
Input and output described in S2, analysis obtain all branches that may be present;
S3, the input and output for analyzing each branch judge whether to need to drive piles, and drive piles if necessary;
S4, all branches are based on, generation unit tests code.
2. the method for automatically generating unit test code according to claim 1, which is characterized in that institute in the step S3 It states and judges whether that needs piling includes:
All output result character strings are traversed, semantic analysis is successively carried out to the character string;
Judge that the character string is the return value of a determining value or a method, does not need then to beat if it is determining value Stake, if it is the return value of a method, then needs to drive piles.
3. the method for automatically generating unit test code according to claim 2, which is characterized in that described in the step S3 Piling includes:
S31, by way of succession, a subclass of class where obtaining being relied on method;
The method being relied on described in S32, rewriting makes the method that is relied on of one subclass return to designated value.
4. the method for automatically generating unit test code according to claim 3, which is characterized in that the step S31 it Before further include:
Whether the class where being relied on method described in judgement is the class or final method that can not be inherited the final rewritten, If so, be relied on the bytecode of class where method described in modification, by it is described be relied on method where class become non-final Class or method.
5. the method for automatically generating unit test code according to claim 1, which is characterized in that the step S1 is also wrapped It includes:
Judge whether to need to modify input, if so, receiving the specified modified input for being directed to to-be-measured cell.
6. a kind of terminal of automatically generating unit test code, including memory, processor and storage are on a memory and can be The computer program run on the processor, which is characterized in that the processor realized when executing the computer program with Lower step:
S1, the specified input and output for being directed to to-be-measured cell are received;
Input and output described in S2, analysis obtain all branches that may be present;
S3, the input and output for analyzing each branch judge whether to need to drive piles, and drive piles if necessary;
S4, all branches are based on, generation unit tests code.
7. the terminal of automatically generating unit test code according to claim 6, which is characterized in that institute in the step S3 It states and judges whether that needs piling includes:
All output result character strings are traversed, semantic analysis is successively carried out to the character string;
Judge that the character string is the return value of a determining value or a method, does not need then to beat if it is determining value Stake, if it is the return value of a method, then needs to drive piles.
8. the terminal of automatically generating unit test code according to claim 7, which is characterized in that described in the step S3 Piling includes:
S31, by way of succession, a subclass of class where obtaining being relied on method;
The method being relied on described in S32, rewriting makes the method that is relied on of one subclass return to designated value.
9. the terminal of automatically generating unit test code according to claim 8, which is characterized in that in the step S31 Before the subclass for obtaining class where being relied on method described later further include:
Whether the class where being relied on method described in judgement is the class or final method that can not be inherited the final rewritten, If so, be relied on the bytecode of class where method described in modification, by it is described be relied on method where class become non-final Class or method.
10. the method for automatically generating unit test code according to claim 6, which is characterized in that the step S1 is also Include:
Judge whether to need to modify input, if so, receiving the specified modified input for being directed to to-be-measured cell.
CN201811004196.6A 2018-08-30 2018-08-30 Method and terminal for automatically generating unit test code Active CN109308260B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811004196.6A CN109308260B (en) 2018-08-30 2018-08-30 Method and terminal for automatically generating unit test code

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811004196.6A CN109308260B (en) 2018-08-30 2018-08-30 Method and terminal for automatically generating unit test code

Publications (2)

Publication Number Publication Date
CN109308260A true CN109308260A (en) 2019-02-05
CN109308260B CN109308260B (en) 2021-11-05

Family

ID=65224090

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811004196.6A Active CN109308260B (en) 2018-08-30 2018-08-30 Method and terminal for automatically generating unit test code

Country Status (1)

Country Link
CN (1) CN109308260B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113656290A (en) * 2021-08-04 2021-11-16 支付宝(杭州)信息技术有限公司 Mock point automatic identification method, device and equipment

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040153830A1 (en) * 2002-09-30 2004-08-05 Ensco, Inc. Method and system for object level software testing
CN101145954A (en) * 2007-06-20 2008-03-19 中兴通讯股份有限公司 Implementation method for piling class of communication function
CN101436128A (en) * 2007-11-16 2009-05-20 北京邮电大学 Software test case automatic generating method and system
CN101706753A (en) * 2009-12-11 2010-05-12 武汉虹信通信技术有限责任公司 Unit testing framework and method based on Perl
CN102419728A (en) * 2011-11-01 2012-04-18 北京邮电大学 Method for determining software test process sufficiency based on coverage rate quantitative indicators
CN103714000A (en) * 2013-12-18 2014-04-09 杭州电子科技大学 Sensitive area-oriented embedded software test case generating method
JP2014063415A (en) * 2012-09-24 2014-04-10 Mitsubishi Electric Corp Test case automatic generation device and test case automatic generation program
CN106874202A (en) * 2017-02-14 2017-06-20 网易无尾熊(杭州)科技有限公司 Method, device and readable storage medium storing program for executing for unit testing
CN107992425A (en) * 2017-12-25 2018-05-04 携程旅游网络技术(上海)有限公司 The automatic generation method and system of unit testing Mock codes

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040153830A1 (en) * 2002-09-30 2004-08-05 Ensco, Inc. Method and system for object level software testing
CN101145954A (en) * 2007-06-20 2008-03-19 中兴通讯股份有限公司 Implementation method for piling class of communication function
CN101436128A (en) * 2007-11-16 2009-05-20 北京邮电大学 Software test case automatic generating method and system
CN101706753A (en) * 2009-12-11 2010-05-12 武汉虹信通信技术有限责任公司 Unit testing framework and method based on Perl
CN102419728A (en) * 2011-11-01 2012-04-18 北京邮电大学 Method for determining software test process sufficiency based on coverage rate quantitative indicators
JP2014063415A (en) * 2012-09-24 2014-04-10 Mitsubishi Electric Corp Test case automatic generation device and test case automatic generation program
CN103714000A (en) * 2013-12-18 2014-04-09 杭州电子科技大学 Sensitive area-oriented embedded software test case generating method
CN106874202A (en) * 2017-02-14 2017-06-20 网易无尾熊(杭州)科技有限公司 Method, device and readable storage medium storing program for executing for unit testing
CN107992425A (en) * 2017-12-25 2018-05-04 携程旅游网络技术(上海)有限公司 The automatic generation method and system of unit testing Mock codes

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113656290A (en) * 2021-08-04 2021-11-16 支付宝(杭州)信息技术有限公司 Mock point automatic identification method, device and equipment

Also Published As

Publication number Publication date
CN109308260B (en) 2021-11-05

Similar Documents

Publication Publication Date Title
Luo Software testing techniques
Taylor et al. Structural testing of concurrent programs
Honglei et al. The research on software metrics and software complexity metrics
Bashir et al. Improved genetic algorithm to reduce mutation testing cost
Eickelmann et al. An evaluation of software test environment architectures
CN109032927A (en) A kind of bug excavation method and device
CN107368408A (en) A kind of software fault towards interface injects automated testing method
US20060248405A1 (en) Method for automating unit test development
Cheon et al. A complete automation of unit testing for Java programs
US20070061641A1 (en) Apparatus and method for generating test driver
Cheon Automated random testing to detect specification-code inconsistencies
CN111752841A (en) Single test simulation method, device, equipment and computer readable storage medium
CN109308260A (en) A kind of method and terminal of automatically generating unit test code
Arora et al. Evaluation of flow graph and dependence graphs for program representation
Han et al. Automated warship software testing system based on loadrunner automation API
Hartman et al. Model driven testing-AGEDIS architecture interfaces and tools
CN116225377A (en) Unified development method and device for cross-platform applet and electronic equipment
Ye et al. Regression test cases generation based on automatic model revision
Hu et al. Automatic black-box method-level test case generation based on constraint logic programming
CN113204765A (en) Method and system for testing HyperLegger Fabric chain code
Maton et al. PseudoSweep: A pseudo-tested code identifier
Saha et al. On the fly mhp analysis
Orjala Unit testing methods for Internet of Things Mbed OS operating system
Honfi et al. Supporting unit test generation via automated isolation
Walker Automatically Generating Test Cases for Data Structures Assignments

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