是否有一个框架可以在 Apache C 模块上运行单元测试?

发布于 2024-07-08 22:12:44 字数 325 浏览 15 评论 0原文

我将对现有的 Apache C 模块进行一些更改,以修复一些可能的安全缺陷和一般的不良做法。 但是,代码的功能必须保持不变(除非修复错误)。 标准回归测试的内容似乎是有序的。 我想知道是否有人知道针对代码运行一些回归单元测试的好方法。 我正在考虑使用 C-Unit 但由于与 Apache APR 和状态结构的所有关联,我想知道是否有一个好的方法来测试它。 例如,是否有任何可以与 C-unit 一起使用的预构建框架?

谢谢

彼得

I am about to make some changes to an existing Apache C module to fix some possible security flaws and general bad practices. However the functionality of the code must remain unchanged (except in cases where its fixing a bug). Standard regression testing stuff seems to be in order. I would like to know if anyone knows of a good way to run some regression unit tests againt the code. I'm thinking something along the lines of using C-Unit but with all the tie ins to the Apache APR and status structures I was wondering if there is a good way to test this. Are there any pre-built frameworks that can be used with C-unit for example?

Thanks

Peter

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

做个少女永远怀春 2024-07-15 22:12:44

我已经考虑回答这个问题有一段时间了,但认为其他人可能会提出更好的答案,因为我的答案相当不满意:不,我不知道有任何这样的单元测试框架。

我认为你最好的选择是尝试重构你的 C 模块,使其对 httpd 代码库的依赖包含在一个非常薄的粘合层中。 我不会太担心对 APR 的依赖,它可以轻松链接到您的单元测试代码中。 就像使用请求记录一样,您应该尝试抽象一些。

如果代码被怀疑包含安全缺陷和不良做法,我将尽可能建议这样的重构是一个好主意。 这通常是一项相当大的工作。

您还可能考虑运行集成测试而不是单元测试(最好是两者),即提出一组请求和来自服务器的预期响应,并运行一个程序来比较实际响应与预期响应。

所以,这不是您一直在寻找的答案,您自己可能也想到了类似的事情。 但至少我可以根据经验告诉您,如果由于业务原因无法用新的模块替换该模块,那么从长远来看,重构它以实现可测试性可能会获得回报。

I've been thinking of answering this for a while, but figured someone else might come up with a better answer, because mine is rather unsatisfactory: no, I'm not aware of any such unit testing framework.

I think your best bet is to try and refactor your C module such that it's dependencies on the httpd code base are contained in a very thin glue layer. I wouldn't worry too much about dependencies on APR, that can easily be linked into your unit test code. It's things like using the request record that you should try to abstract out a little bit.

I'll go as far and suggest that such a refactoring is a good idea if the code is suspected to contain security flaws and bad practices. It's just usually a pretty big job.

What you might also consider is running integration tests rather than unit tests (ideally both), i.e. come up with a set of requests and expected responses from the server, and run a program to compare the actual to expected responses.

So, not the response you've been looking for, and you probably thought of something along this line yourself. But at least I can tell you from experience that if the module can't be replaced with something new for business reasons, then refactoring it for testability will likely pay off in the longer term.

嘿嘿嘿 2024-07-15 22:12:44

花了一些时间在互联网上寻找你,因为这是一个我自己很好奇的问题。 遇到一篇 wiki 文章,指出

http://cutest.sourceforge.net/

用于 apache 便携式c 运行时测试。 可能值得检查一下。

Spent some time looking around the interwebs for you as its a question i was curious myself. came across a wiki article stating that

http://cutest.sourceforge.net/

was used for the apache portable c runtime testing. might be worth checking that out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文