Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to carry out the practice of code change test coverage of graph database Nebula Graph

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

In this issue, the editor will bring you the practice of code change test coverage on how to carry out the graph database Nebula Graph. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

For a large-scale project of continuous development, adequate testing is an effective means to ensure that the software behavior is in line with expectations, rather than relying solely on code review or the developer's own technical quality. The writing of tests should ideally fully define the behavior of the software, but it is often difficult to reach such an ideal level. The test coverage is to verify the behavior of the test coverage software, by checking the test coverage can help developers to find the code that is not covered.

Test coverage information collection

Nebula Graph is mainly developed by C++ language and supports most Linux environments and gcc/clang compilers, so through the support provided by the tool chain, we can easily count the test coverage of Nebula Graph.

Gcc/clang supports gcov-style test coverage, and it is very easy to use. The main steps are as follows:

Add compilation option-- coverage-O0-g

Add Link option-coverage

Run the test

Using lcov, integrate reports, such as lcov-- capture-- directory. -- output-file coverage.info

Remove external code statistics, such as lcov-- remove coverage.info'* / opt/vesoft/*'-o clean.info

Now that the test coverage information has been collected, you can generate html through tools such as genhtml, and then view the test coverage through the browser, as shown in the following figure:

But this is very inconvenient, because in the continuous development process, if you have to do such a set of operations manually every time, it will inevitably lead to a great waste of manpower, so now the common practice is to write test coverage into CI and integrate with third-party platforms (such as Codecov, Coveralls), so that developers do not have to care about the collection, collation and display of test coverage information. You only need to release the code and go directly to the third-party platform to check the coverage, and the current third-party platform also supports commenting on the coverage directly on the PR to make it more convenient to view the changes in coverage.

Integrated CI Github Action

Now there are many mainstream CI platforms, such as Travis, azure-pipelines, GitHub Action and so on. GitHub Action is selected for Nebula Graph, and we have already introduced Action in our previous article, "using Github Action for Front-end Automation release."

Compared with other CI platforms, GitHub Action has the advantages of better integration with GitHub, powerful, simple and easy to use Action and supporting a considerable number of operating systems and CPU. The snippet of Nebula Graph's CI script about test coverage is as follows:

-name: CMake with Coverage if: matrix.compiler = = 'gcc-9.2' & & matrix.os = =' centos7' run: | cmake-DENABLE_COVERAGE=ON-B build/

You can see here that we manage the coverage-related compilation options described earlier through a cmake option, which makes it very easy to enable and disable the collection of coverage information. For example, developers usually do not turn on this feature during the normal development, compilation and testing process to avoid the extra overhead of compiling and testing.

-name: Testing Coverage Report working-directory: build if: success () & & matrix.compiler = = 'gcc-9.2' & & matrix.os = =' centos7' run: | set-e / usr/local/bin/lcov-version / usr/local/bin/lcov-capture-gcov-tool $GCOV-directory. -- output-file coverage.info / usr/local/bin/lcov-- remove coverage.info'* / opt/vesoft/*'-o clean.info bash

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report