0

我有一个第三方软件,它能够使用以下方式运行一些 python 脚本:

software.exe -script pythonscript.py

我的公司严重依赖这个软件以及我们为它开发的脚本。目前我们有一些 QA 来检查脚本的输出,但我们真的想开始对脚本进行单元测试,以便更容易发现错误并使测试系统更加完整。

我的问题是如何运行“嵌入式”单元测试?我们使用 pydev+eclipse,我尝试使用它的远程调试来使其与单元测试一起工作,但我不能真正让它工作。如何使服务器连接“馈送”单元测试?

另一个想法是解析软件的标准输出,但这并不是真正的单元测试......而且它似乎带来的额外复杂性使得这种方法不那么有趣。

我希望这样的事情已经在其他地方完成了,我尝试用谷歌搜索它,但也许我只是没有使用正确的关键字。谁能给我一个起点?

谢谢

4

3 回答 3

1

更多信息会有所帮助。您是否使用了测试框架(例如 unittest 或 nose),或者如果没有,测试的结构如何?是什么software.exe

在 python 中,单元测试实际上只不过是在失败时引发异常的函数的集合,因此它们可以像任何其他函数一样从脚本中调用。因此,理论上,您可以简单地创建一个测试运行程序(如果您还没有使用诸如鼻子之类的运行程序),并将其运行为software.exe -script runtests.py. 在 pydev 中,您可以设置software.exe为自定义的 python 解释器。

如果问题是software.exe隐藏了标准输出,那么只需将结果写入日志文件即可。您还可以创建一个模拟由提供的环境software.exe并使用python.exe.

于 2012-10-30T11:33:59.743 回答
0

如果单元测试适用于您的代码而不是提供的功能,那么您可以在必要时software.exe使用独立的 python 模拟部件运行测试。software.exe作为中间步骤,您可以尝试unittest使用“software.exe”运行基于脚本的脚本

于 2012-10-30T11:29:58.637 回答
0

好吧,一般来说,测试软件应由持续集成套件完成(并且Jenkins是您的朋友)。

Now, I think you'll have to test your scripts pythonscript.py by setting a test() function inside the python script that will emulate the possible environments you'll give to the entry point of your script. And you'll be able to use unittest to execute the test functions of all your scripts. You can also embed tests in doctests, but I personally don't like that.

And then, in your software.exe, you'll be able to execute tests by emulating all the environment combinations. But as you don't say much about software.exe I won't be able to help you more... (what language ? is software.exe already unit tested ?)

于 2012-10-30T11:34:16.123 回答