c语言桌面程序 touch unity,使用unity做C语言自动测试.docx

本文介绍了如何在Ubuntu环境下使用Unity框架进行Test-Driven Development (TDD),包括源代码结构、Unity框架的应用、测试代码编译与运行过程,以及自动生成测试容器Runner的步骤。重点讲解了模块化设计和Unity作为独立模块的编译方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值