Unlock instant, AI-driven research and patent intelligence for your innovation.

A method and terminal for automatically generating unit test code

A unit testing, automatic generation technology, applied in software testing/debugging, error detection/correction, instruments, etc., can solve the problem of time-consuming and laborious, and achieve the effect of reducing tedious and repetitive work, improving work efficiency and saving time

Active Publication Date: 2019-02-05
FUJIAN TIANQUAN EDUCATION TECH LTD
View PDF9 Cites 0 Cited by
  • Summary
  • Abstract
  • Description
  • Claims
  • Application Information

AI Technical Summary

Problems solved by technology

[0005] All in all, unit testing is very important, but under the traditional unit testing framework, programmers are unwilling to write it. Unit testing requires testers to learn a third-party testing framework, write a lot of repetitive code and continue to test Maintenance also requires testers to master piling technology, which is time-consuming and laborious

Method used

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
View more

Image

Smart Image Click on the blue labels to locate them in the text.
Viewing Examples
Smart Image
  • A method and terminal for automatically generating unit test code
  • A method and terminal for automatically generating unit test code
  • A method and terminal for automatically generating unit test code

Examples

Experimental program
Comparison scheme
Effect test

Embodiment 1

[0059] Please refer to figure 1 , a method to automatically generate unit tests, including steps:

[0060] S1. Receive specified input and output for the unit under test;

[0061] Wherein, the input refers to the condition of the if statement in the code, and the output refers to the result when the condition is satisfied or not satisfied. If the source code of the unit under test is changed, such as by changing the three parameters into four parameters, 16 test cases need to be rewritten under the traditional method, but the present invention only needs to modify the input conditions, and the test cases can be automatically regenerated;

[0062] S2. Analyzing the input and output to obtain all possible branches;

[0063] S3. Analyze the input and output of each branch to determine whether piling is required, and if necessary, piling;

[0064] Specifically, by traversing all output result strings, perform semantic analysis on the strings in turn; judge whether the string is...

Embodiment 2

[0070] Apply the method described in Embodiment 1 to a specific example, in the java test:

[0071] First, the system provides the following methods for inputting parameters:

[0072] a). The method of setting conditions (hereinafter referred to as the if method), this method is used to receive the conditional statement provided by the developer. Suppose there is such a statement: return a>0? 1:0, the condition is "a>0" ;

[0073] b). The method of setting the return value when the condition is met (hereinafter referred to as the then method). This method is used to receive the value when the condition given in the if method provided by the developer is met. Taking the above statement as an example, it is "1" ;

[0074] c). The method of setting the return value when the condition is not met (hereinafter referred to as the else method). This method is used to receive the value when the condition given in the if method provided by the developer is not met. Taking the above st...

Embodiment 3

[0097] Apply the method described in Embodiment 2 to a specific example, in the java test:

[0098] Suppose a developer wants to write a unit test case for the following piece of code:

[0099] public class Foo{

[0100] public int getValue(int value1,int value2,int value3){

[0101] if(value1>0||value2>0||value3>0){

[0102] return MathTools. next(value1, value2, value3);

[0103]}

[0104] return 0;

[0105]}

[0106]}

[0107]The core of this code is only three lines, and the result is: when the three input parameters are all natural numbers, return the return value (MathTools.next) of a method of another class, otherwise return 0; Branch coverage will write 8 test cases, and it will take a lot of time to add later maintenance. In the case of using the solution of the present invention, the process is as follows:

[0108] S1. Receive the specified input and output for the unit under test, specifically:

[0109] (1) First, the developer calls the if method and enters t...

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to View More

PUM

No PUM Login to View More

Abstract

The invention discloses a method and a terminal for automatically generating a unit test code, By receiving the specified input and output for the unit under test, analyzing the input and output to obtain all possible branches, Then, the input and output of each branch are analyzed to determine whether piling is needed or not, and if so, the unit test code is generated based on all branches, whichcan realize automatic generation of unit test code, reduce tedious and repetitive work, and can be used in later maintenance, save time and improve work efficiency.

Description

technical field [0001] The invention relates to the technical field of software testing, in particular to a method and terminal for automatically generating unit testing codes. Background technique [0002] A unit test is a small piece of code written by the developer to check whether a small, clear function of the code under test is correct. Generally speaking, a unit test is used to judge the behavior of a specific function under a specific condition or scenario. Unit testing is the most basic and important means of code function and robustness, and it is a very important link in the whole software engineering. [0003] However, writing unit tests is cumbersome and time-consuming. If there is a judgment statement consisting of three conditions in a method, then its complete branch coverage must be achieved (the so-called branch coverage means that the code of the unit test must run through all branches) , the developer needs to write 2 3 =8 test cases, the more branches...

Claims

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to View More

Application Information

Patent Timeline
no application Login to View More
Patent Type & Authority Applications(China)
IPC IPC(8): G06F11/36
CPCG06F11/3684
Inventor 刘德建陈斌杨宏群鄢宜扬郭玉湖
Owner FUJIAN TIANQUAN EDUCATION TECH LTD