test: improve unit test coverage to 62% and fix stale expectations#691
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
|
Note
详情{
"deepin-devicemanager/tests/src/DriverControl/ut_httpdriverinterface.cpp": [
{
"line": " EXPECT_STREQ(\"http://example.com/d.deb\", d0.strDeb.toStdString().c_str());",
"line_number": 94,
"rule": "S35",
"reason": "Url link | 82eb1a6f74"
}
]
} |
Add new unit tests for low-coverage classes to raise line coverage above 60%. 为低覆盖类新增单元测试,将行覆盖率提升至60%以上。 Fix 56 stale test expectations to match current source behavior. 修复56个过时的测试期望,使其匹配当前源码行为。 Exclude vendored 3rdparty from coverage stats in the test script. 测试脚本中排除第三方代码,避免其误计入项目覆盖率统计。 Log: 提升单元测试覆盖率至62% Influence: 行覆盖率由45.3%提升至62.0%,全部791个测试通过,零失败。
48b4c6e to
e79c546
Compare
|
Note
详情{
"deepin-devicemanager/tests/src/DriverControl/ut_httpdriverinterface.cpp": [
{
"line": " EXPECT_STREQ(\"http://example.com/d.deb\", d0.strDeb.toStdString().c_str());",
"line_number": 94,
"rule": "S35",
"reason": "Url link | 82eb1a6f74"
}
]
} |
|
[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 |
deepin pr auto review★ 总体评分:95分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // ut_dbuswakeupinterface.cpp 修复内存泄漏与文件依赖
void SetUp() override
{
m_iface = DBusWakeupInterface::getInstance();
m_origInputIface = m_iface->mp_InputIface;
m_origIface = m_iface->mp_Iface;
m_iface->mp_InputIface = nullptr;
// 使用局部对象管理内存,避免泄漏
m_fakeIface = new QDBusInterface("org.nonexistent.NoService", "/x",
"org.nonexistent.NoService",
QDBusConnection::systemBus());
m_iface->mp_Iface = m_fakeIface;
// 创建临时文件替代依赖 /etc/hostname
m_tmpFile = new QTemporaryFile(this);
if (m_tmpFile->open()) {
m_tmpFilePath = m_tmpFile->fileName();
}
}
void TearDown() override
{
// 恢复原始指针
m_iface->mp_InputIface = m_origInputIface;
m_iface->mp_Iface = m_origIface;
// 释放动态创建的对象
if (m_fakeIface) {
delete m_fakeIface;
m_fakeIface = nullptr;
}
// 临时文件由 Qt 对象树自动清理
}
// 对应的测试用例修改
TEST_F(UT_DBusWakeupInterface, UT_DBusWakeupInterface_canInputWakeupMachine_exists)
{
EXPECT_TRUE(m_iface->canInputWakeupMachine(m_tmpFilePath));
}
TEST_F(UT_DBusWakeupInterface, UT_DBusWakeupInterface_canInputWakeupMachine_missing)
{
EXPECT_FALSE(m_iface->canInputWakeupMachine("/tmp/nonexistent-wakeup-file-12345"));
}
private:
QDBusInterface *m_fakeIface = nullptr;
QTemporaryFile *m_tmpFile = nullptr;
QString m_tmpFilePath; |
|
/merge |
Add new unit tests for low-coverage classes to raise line coverage above 60%.
为低覆盖类新增单元测试,将行覆盖率提升至60%以上。
Fix 56 stale test expectations to match current source behavior.
修复56个过时的测试期望,使其匹配当前源码行为。
Exclude vendored 3rdparty from coverage stats in the test script.
测试脚本中排除第三方代码,避免其误计入项目覆盖率统计。
Log: 提升单元测试覆盖率至62%
Influence: 行覆盖率由45.3%提升至62.0%,全部791个测试通过,零失败。