如何测试静态函数 [英] How to test a static function

查看:29
本文介绍了如何测试静态函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在对一些C代码应用单元测试时,我们遇到了在不修改源代码的情况下无法在测试文件中调用某些静态函数的问题.有什么简单或合理的方法可以解决这个问题吗?

As applying unit-test to some C code, we run into a problem that some static function can not be called at the test file, without modifying the source code. Is there any simple or reasonable way to overcome this problem?

推荐答案

我有一个测试工具.在可怕的情况下——比如尝试测试一个静态函数,我使用:

I have a test harness. In dire cases - like trying to test a static function, I use:

#include "code_under_test.c"
...test framework...

也就是说,我在测试工具中包含了包含被测函数的整个文件.这是最后的手段 - 但它有效.

That is, I include the whole of the file containing the function under test in the test harness. It is a last resort - but it works.

这篇关于如何测试静态函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆