在 Perl 中进行单元测试期间提示用户
我正在编写一个模块,该模块具有需要运行某个外部服务器程序的单元测试,如果是,则需要知道主机名和端口。
我想在运行测试套件时提示输入此信息,并在用户拒绝提供时跳过这些测试。
处理这个问题的最佳方法是什么?
谢谢
I'm writing a module which has unit tests that require a certain external server program to be running, and, if it is, the hostname and port need to be known.
I would like to prompt for this information when running the test suite, and skip those tests if the user declines to provide it.
What's the best way to handle this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否在寻找
ExtUtils::MakeMaker::prompt
?Are you looking for
ExtUtils::MakeMaker::prompt
?我将对此采取不同的策略。为什么您需要用户作为中间人 - 特别是对于自动化测试?一个明显更好的方法(根据我自己的经验)是执行以下操作之一:
使服务器(主机名/端口)可以通过测试以某种方式发现。它可以是真正的可发现性,或者让服务器自行注册,或者,哎呀,一些配置服务。考虑到现实世界中服务器的客户端需要能够连接到服务器,这样的发现逻辑(同样,最坏的情况是某些配置文件)应该已经存在。
对于真正高级的情况,允许测试工具能够在测试端口上启动服务器的测试实例(如果服务器的测试实例未运行)。
请注意,如果您的服务器由于某种原因无法进行检测以允许上述任何一种方法,那么套接字木偶的答案是最好的方法。
I'll take a different tack on this. Why exactly do you need the user as a middleman for this - especially for automated tests? A significantly better approach (from my own experience) is to do one of the following:
Make the server (hostname/port) somehow discoverable by the test. It can be either a genuine discoverability, or having the server register itself, or, heck, some config service. Considering that the server's clients in real world would need to be able to connect to the server, such a discovery logic (again, worst case scenario being some config file) should already exist.
For a really advanced case, allow the test harness the ability to start the test instance of a server on a test port if one is not running.
Mind you, if your server for some reason can not be instrumented to allow either of the approaches above, then socket puppet's answer is the best approach.