告别代码,让Openharmony软总线测试用例跑起来!!! 原创 精华
告别代码,让Openharmony软总线测试用例跑起来!!!
dsoftbus_standard目的:
openharmony 软总线代码过于庞大,而且其中有很多地方的功能并没完善,走读代码应该是一种比较痛苦的方法。此次介绍如何使用软总线测试用例,来更深入了解软总线,当然超越自我,你也可以按图索骥,编写自己的测试用例,用来加深对软总的理解,或者往社区中提出自己发现的bug.
准备:
下载最新代码,不过在此之前你需要了解GN ninja等编译原理,此次教程我们将使用软总线已有的测试用例,
开始啦
打开foundation/communication/dsoftbus/ohos.build
dsoftbus_standard 中系统是按照先后顺序执行编译,如需增加自己新增的测试用例,可以往test_list后面增加编译模块。
进入foundation/communication/dsoftbus/tests/sdk/discovery/unittest,打开BUILD.gn
这里是编译测试用例
测试用例文件
tests/sdk/discovery/unittest/disc_sdk_test.cpp
编译
执行
./build.sh --product-name Hi3516DV300 --build-target DiscSdkTest
注意,需要先执行./build.sh --product-name Hi3516DV300 将相关依赖的库编译,否则会出现编译失败的情况。
编译完成之后,可以在下面目录中找到对应问题测试模块DiscSdkTest
./out/ohos-arm-release/tests/unittest/dsoftbus_standard/discovery/
编译完成。
结果
将DiscSdkTest 上传到板子,
执行 chmod 0755 DiscSdkTest 给予执行权限
./DiscSdkTest
结果
chmod 0755 DiscSdkTest
./DiscSdkTest
Running main() from …/…/third_party/googletest/googletest/src/gtest_main.cc
[==========] Running 12 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 12 tests from Disc_Test
[ RUN ] Disc_Test.PublishServiceTest001
[ OK ] Disc_Test.PublishServiceTest001 (8 ms)
[ RUN ] Disc_Test.PublishServiceTest002
[ OK ] Disc_Test.PublishServiceTest002 (3 ms)
[ RUN ] Disc_Test.PublishServiceTest003
[ OK ] Disc_Test.PublishServiceTest003 (5 ms)
[ RUN ] Disc_Test.StartDiscoveryTest001
[ OK ] Disc_Test.StartDiscoveryTest001 (2 ms)
[ RUN ] Disc_Test.StartDiscoveryTest002
[ OK ] Disc_Test.StartDiscoveryTest002 (4 ms)
[ RUN ] Disc_Test.StartDiscoveryTest003
[ OK ] Disc_Test.StartDiscoveryTest003 (10 ms)
[ RUN ] Disc_Test.UnPublishServiceTest001
[ OK ] Disc_Test.UnPublishServiceTest001 (3 ms)
[ RUN ] Disc_Test.UnPublishServiceTest002
[ OK ] Disc_Test.UnPublishServiceTest002 (9 ms)
[ RUN ] Disc_Test.UnPublishServiceTest003
[ OK ] Disc_Test.UnPublishServiceTest003 (7 ms)
[ RUN ] Disc_Test.StopDiscoveryTest001
[ OK ] Disc_Test.StopDiscoveryTest001 (14 ms)
[ RUN ] Disc_Test.StopDiscoveryTest002
[ OK ] Disc_Test.StopDiscoveryTest002 (15 ms)
[ RUN ] Disc_Test.StopDiscoveryTest003
[ OK ] Disc_Test.StopDiscoveryTest003 (25 ms)
[----------] 12 tests from Disc_Test (110 ms total)
[----------] Global test environment tear-down
Gtest xml output finished
[==========] 12 tests from 1 test case ran. (111 ms total)
[ PASSED ] 12 tests.
软总线测试用例测试完成,结果OK,本期到此结束,下期再会!
感谢大佬讲解,自己走读确实坑点太多了
666