看到 cleanfight 下面有 test/unit, 估计是做单元测试用的
一个make (Ubuntu下面) 都编译了,再到 cleanflight/obj/test 生成了很多可执行文件
原来 cleanflight的单元测试不是是stm32上跑了,而是在pc上跑,主要测试函数的功能
找个源元件,原来是用gtest写的,下面就在 cleanflight目录下做 gtest的试验
1)编写一个文件叫 1.c
======= 1.c ============
#include "gtest/gtest.h"
TEST (SquareRootTest, PositiveNos) {
EXPECT_EQ (18.0, 18.0);
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
g++ -isystem ./lib/test/gtest/inc 1.c ./obj/test/gtest-all.o -o 1 -lpthread
3)运行得到结果
$ ./1
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from SquareRootTest
[ RUN ] SquareRootTest.PositiveNos
[ OK ] Squar

本文介绍了如何在Ubuntu环境下使用gtest进行单元测试。首先通过make命令编译生成了cleanflight/obj/test目录下的可执行文件。然后,了解到这些测试主要是针对函数功能的,而非在STM32上运行。接着,作者创建了一个名为1.c的测试文件,并展示了运行测试得到的结果,所有1个测试用例均成功通过。
最低0.47元/天 解锁文章
717

被折叠的 条评论
为什么被折叠?



