Jacoco coverage merging and call link analysis in precise testing

Target

code coverage

  • Different versions of coverage data can be merged (the granularity of merging is the logic branch of the code)
  • View the latest coverage reports in real time

link analysis

  • Record function call chain: the smallest unit is the code logic branch in the function
  • Automatically correlate interface use cases and function use cases. Automatically recommend affected interface use cases and function use cases by analyzing code change records

code coverage

In order to view the coverage report more intuitively later, the test code is placed in the same class.
The test code is as follows:

@RestController
@RequestMapping("/api/account")
public class LoginController {

    @GetMapping("/login")
    public Result login(@RequestParam(required = false) String name,
                        @RequestParam(required = false) String passwd){
        if (StringUtils.isEmpty(name)){
            System.out.println("用户名不能为空");
            return Result.error("用户名不能为空");
        }
        if (StringUtils.isEmpty(passwd)){
            System.out.println("用户密码不能为空");
            return Result.error("用户密码不能为空");
        }
        if (!"123456".equals(passwd)){
            System.out.println("用户密码错误");
            return Result.error("用户密码错误");
        }
        test1(name);
        if ("admin".equals(name)){
            System.out.println("管理员登录成功");
            return Result.success("管理员登录成功");
        }
        System.out.println(name+"登录成功");
        return Result.success(name+"登录成功");
    }

    @GetMapping("/info")
    public Result info(){
        return Result.success("用户信息获取成功");
    }

    private void test1(String name){
        if ("admin".equals(name)){
            System.out.println("登录用户是管理员, 拥有全部权限");
        }
        else {
            System.out.println("当前是普通用户,设置部分权限");
            new Runnable(){
                @Override
                public void run() {
                    System.out.println("设置登录用户积分");
                }
            }.run();
        }
        System.out.println("权限处理完毕");
    }
}

In this code, there are 5 executable call chains in the login interface, and the corresponding http request information is as follows:

  • 127.0.0.1:7020/api/account/login
  • 127.0.0.1:7020/api/account/login?name=test
  • 127.0.0.1:7020/api/account/login?name=test&passwd=111111
  • 127.0.0.1:7020/api/account/login?name=test&passwd=123456
  • 127.0.0.1:7020/api/account/login?name=admin&passwd=123456

Execute the above five requests one by one, and click to generate the coverage report as follows:


It can be seen that the five calling paths of the login interface have all been executed

Modify the test code:

insert image description here
Submit the code and redeploy the test service
Request info interface:

  • 127.0.0.1:7020/api/account/info

Click on the platform page to generate a coverage report:


It can be seen from the report that the effective part of the data collected for the first time is retained, and the code coverage data of the request info interface after redeploying the service is merged.

The invalid data in the first data collection is removed: the code related to the test user login is changed, so the invalid coverage data of the test user login is cleared.

Call chain analysis

Association Interface Use Case

In the test plan configuration of the interface automation module, the functions of coverage collection, traffic recording and recording call chain can be enabled with one click


2. In the generated test report, you can view the coverage data and the function call chain corresponding to each use case


3. At the same time, it supports direct and automatic mock playback of the interface request to quickly locate interface problems

Analysis call chain

Call chain analysis adopts dynamic and static combination. Obtain the function dynamic call chain by associating the use case, and the call chain data is saved in es. By analyzing code changes, the affected use case data can be accurately obtained. For some newly added functions, through static code analysis, the static call chain data is saved with neo4j. Static code analysis is mainly used in the design to make up for the newly added entry function without recording the call chain, and then confirm the affected range by analyzing the function call chain of the source code. This method cannot accurately obtain the affected interface. Example. So it mainly depends on the dynamic call chain to do it.

On the platform, requests to analyze the call chain affect changes


For the results in the above figure, it can be roughly divided into the accurate analysis of data such as the affected interface use cases and the range data affecting the interface use cases obtained through static code analysis.

Finally : In order to give back to the die-hard fans, I have compiled a complete software testing video learning tutorial for you. If you need it, you can get it for free【保证100%免费】

Software Testing Interview Documentation

We must study to find a high-paying job. The following interview questions are the latest interview materials from first-tier Internet companies such as Ali, Tencent, and Byte, and some Byte bosses have given authoritative answers. Finish this set The interview materials believe that everyone can find a satisfactory job.

全部资料获取:

insert image description here

Guess you like

Origin blog.csdn.net/weixin_54696666/article/details/131586507