test: expand unit tests to lift src/ coverage from ~58% to ~60%#866
Conversation
There was a problem hiding this comment.
Sorry @pengfeixx, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
Add tests for dbus_name/constant/delaytime/shapesutils/previewwidget/ screengrabber/toolbutton/maintoolwidget/event_monitor/main_window EF helpers, and guard forceToExitApp() with ENABLE_UNIT_TEST. Also extend lcov exclusions for untestable Wayland/X11/camera code. 新增多个源文件的单元测试(dbus_name/constant/delaytime/shapesutils/ previewwidget/screengrabber/toolbutton/maintoolwidget/event_monitor/ main_window 事件过滤助手等),并用 ENABLE_UNIT_TEST 宏守卫 forceToExitApp 避免测试进程退出;同时扩展 lcov 排除项,剔除无法 单测的 Wayland/X11/摄像头相关代码。 Log: 提升单元测试覆盖率 Influence: 扩充单元测试覆盖面,src/ 行覆盖率由约58%提升至约60%,为后续达到80%奠定基础;源码改动均以 ENABLE_UNIT_TEST 宏守卫,不影响正式构建行为。
deepin pr auto review★ 总体评分:95分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // 提取 MainWindow 测试的公共基类,消除 ut_main_window_ext.h 与 ut_main_window_ef.h 中的重复代码
// 文件:tests/ut_screen_shot_recorder/ut_main_window_common.h
#pragma once
#include <gtest/gtest.h>
#include <QRect>
#include "stub.h"
#include "addr_pri.h"
#include "../../src/main_window.h"
class MainWindowTestBase : public testing::Test
{
public:
Stub stub;
MainWindow *m_w = nullptr;
// 复刻 ut_main_window.h 的安全构造桩
static QRect geometry_stub() { return QRect(0, 0, 1920, 1080); }
static void passInputEvent_stub(void *, int, int, int, int) { return; }
static qreal devicePixelRatio_stub() { return 1.0; }
static int width_stub() { return 1920; }
static int height_stub() { return 1080; }
void SetUp() override
{
stub.set(ADDR(QScreen, geometry), geometry_stub);
stub.set(ADDR(Utils, passInputEvent), passInputEvent_stub);
stub.set(ADDR(QScreen, devicePixelRatio), devicePixelRatio_stub);
stub.set(ADDR(QWidget, width), width_stub);
stub.set(ADDR(QWidget, height), height_stub);
m_w = new MainWindow;
m_w->initAttributes();
m_w->initResource();
}
// 故意泄漏 m_w,避免无显示 ASAN 环境下析构崩溃
void TearDown() override { }
}; |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, pengfeixx The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/merge |
Add tests for dbus_name/constant/delaytime/shapesutils/previewwidget/ screengrabber/toolbutton/maintoolwidget/event_monitor/main_window EF helpers, and guard forceToExitApp() with ENABLE_UNIT_TEST. Also extend lcov exclusions for untestable Wayland/X11/camera code.
新增多个源文件的单元测试(dbus_name/constant/delaytime/shapesutils/ previewwidget/screengrabber/toolbutton/maintoolwidget/event_monitor/ main_window 事件过滤助手等),并用 ENABLE_UNIT_TEST 宏守卫
forceToExitApp 避免测试进程退出;同时扩展 lcov 排除项,剔除无法
单测的 Wayland/X11/摄像头相关代码。
Log: 提升单元测试覆盖率
Influence: 扩充单元测试覆盖面,src/ 行覆盖率由约58%提升至约60%,为后续达到80%奠定基础;源码改动均以 ENABLE_UNIT_TEST 宏守卫,不影响正式构建行为。