在单元测试中经常需要动态的替换被测函数调用的其他函数,这个替换叫做打桩,现在很少有动态打桩的函数,研究了许久,写了这个功能,做成了lib库,在cygwin下生成的。 给出了一个Demo,使用makefile试一试吧! ps:我目前只在windowsxp下应用,其他平台未知!欢迎发邮件给我。 #include "stdio.h" #include "d_stub.h" void testfunc(int arg, int a, int b, int c) { printf("\tI am testFunc %d\n", arg); } void testfunc1(int arg, int a, int b, int c) { printf("\t******************\n\tI am stub function\n"); printf("\tArguments: %d %d %d %d\n\t******************\n", arg, a, b, c); } void testfunc2(int arg, int a, int b, int c) { printf("\tHello world\n"); } main() { stubInfo si, ss; printf("call original func:\n"); testfunc(1, 2, 3, 4); setStub(testfunc, testfunc1, &si); setStub(testfunc1, testfunc2, &ss); printf("after set stub for func1 and func2:\n"); testfunc(1, 2, 3, 4); cleanStub(&ss); /*recover testfunc1*/ printf("after clear stub for func2:\n"); testfunc(1, 2, 3, 4); cleanStub(&si); /*recover testfunc*/ printf("after clear stub for func1::\n"); testfunc(1, 2, 3, 4); }
2021-06-06 21:21:42 2KB 动态打桩 单元测试 UT 打桩
1
这是一个单元测试打桩开源代码,在git上下载的代码在ARM平台上有一个BUG,使用stub.h中的reset方法时,会引起段错误,该资源对这个bug进行了修复。
2021-02-04 22:03:55 2.17MB c++ 单元测试 stub(打桩) cpp-stub开源代码
1
单元测试打桩开源库 cpp-stub 使用手册 中文版本,这是从git上直接下载的,git上下载的源代码在arm上调用Stub.reset方法会引发段错误,在资源cpp-stub开源代码(下载地址:https://download.csdn.net/download/zhao_sh/15051839)有解决该bug的源代码下载。
1
自己制作的Mockpp介绍文档。 Mockpp是一个开源的C++打桩工具,一般被用在C++的单元测试中。 目前Mockpp没有中文的使用文档,本文用来抛砖引玉。
2021-01-31 18:54:40 2.8MB Mockpp 打桩 c++ cppunit
1