root@ubuntu:~/TDD/proj# tree
一 src
|-- demo.c
一 demo?h
一 test
-- demo_test_group1?c
-- demo_test_groupl?out -- demo_test_groupl_Runner.c --demo_test_group2?c
■- demo_test_group2.out
一 demo_test_group2_Runner.c —makefile
、一 unity
p「oj为工程(相当于模块)
src为产品代码demo.c为源文件,demo.h为头文件 test为测试代码,里面包含了 unity的源码 编译:
在test下meke,将产品代码+测试代码+unity 一起编译 编出两个.out可以直接运行(若一个group则只一个.out) 注:
demo_test_group 1 /2_Runner.c 是口 动生成的运行容器 实际工程中的代码结构可设计为:
moudule
-inc
??tcst模块的测试代码,依赖模块代码和unity框架代码(即include这两个.h) unity作为一个模块,另外编译
(可以当做交换驱动一样的东西,单独编译,然后提供.h即提供api给上层调用)
2、操作步骤
(1)将p呵文件夹放到/root/TDD文件夹下
[root@localhost TDD]# pwd
/root/TDD
[root@localhost TDD]# tree
■
I-- ThrowTheSwitch-Unity-8661f3f?tar?gz 、——proj
| 一 src
|| ——demo ? c
I'一 demo?h
、——test
I-- demo_tesc_group1? c
| -- denio_test_group2 ? c 、一makefile
3 directories, 6 files
[root@localhost TDD]# |
(2)将unity源码解压,复制到test/unity处
[root@localhost TDD]# rav ThrowTheSwitch-Unity-8661f3f proj/test/unity
(3)使用自动生成脚本生成测试容器(Runner)
进入 /root/TDD/proj/test/运行命令(注:若无 ruby 则用 apt-get install ruby 安装) ruby unity/auto/generate_test_runner.rb demo_test_group l.c
ruby unity/auto/generate_test_runner.rb demo_test_group2.c
会自动根据相应.c生成两个*_Runner.c文件
总计24[roocQlocalhost test]# ruby
总计24
root
root
388
09-13
root.
root
1016
09-13
root
root
465
09-13
root
root
1020
root
root
1347
09-13
root
root
4096
09-07
-rwxr-xr-x drwxruxr-x [root0localhost test]#110111
-rwxr-xr-x drwxruxr-x [root0localhost test]#
1
10
1
1
1
10:39 demo_test_groupl_Runner?c
10:14 deino_test_group2 ? c
10:40 demo test group2 Runner.c
10:10 inakef ile
07:20 unity
(4)编译&运行
编译:
make即可
会编出两个.out
运行:
./demo_test_group l.out
./demo_test_group2.out
也可以将运行命令写入到makefile中,编译测试一步完成 如在最后加./$(TARGET1)
default:
#ruby auto/generate_test_runner?rb test/TestProductionCode?c test/no_ruby/
TestProductionCode_Runner?c
e$(C_COMPILER) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES1) -O $(TARGET1) ^(C^COMPILER) $(INC2DIRS) $(SYMBOLS) $(SRC【F1LES2) -o $(TARGET2) ./$(TARGET1)
./$(TARGET2)
结果:
rootKubuntu:*/TDD/proj/test# ma